aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/main/java
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2018-10-23 09:43:26 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2018-10-23 11:12:46 -0400
commit714f7312ef66123ae7cf5a01dbb1c57701733294 (patch)
tree0137314f502dd9d9ae083faa76fab0072b693de7 /mso-api-handlers/mso-api-handler-infra/src/main/java
parentad99d2f0c59ce54e7283c210418d1f234191718b (diff)
default cloud owner now configurable
default cloud owner can now be set via a property Change-Id: I9b900cb2a5c7176a78e889ad2ce31a4ed9d38585 Issue-ID: SO-1158 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/SpringContextHelper.java42
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java2
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java2
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/dmaap/DmaapPropertiesImpl.java2
4 files changed, 3 insertions, 45 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/SpringContextHelper.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/SpringContextHelper.java
deleted file mode 100644
index 6d61d3bb34..0000000000
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/SpringContextHelper.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Modifications Copyright (C) 2018 IBM.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.so.apihandlerinfra;
-
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.stereotype.Component;
-
-@Component
-public class SpringContextHelper implements ApplicationContextAware {
-
- private static ApplicationContext context;
-
- @Override
- public void setApplicationContext(ApplicationContext applicationContext) {
- context = applicationContext;
- }
-
- public static ApplicationContext getAppContext() {
- return context;
- }
-}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java
index 5675588f62..1ea77acf95 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java
@@ -23,9 +23,9 @@ package org.onap.so.apihandlerinfra.tenantisolation;
import java.net.MalformedURLException;
import java.net.URL;
-import org.onap.so.apihandlerinfra.SpringContextHelper;
import org.onap.so.client.aai.AAIProperties;
import org.onap.so.client.aai.AAIVersion;
+import org.onap.so.spring.SpringContextHelper;
import org.springframework.context.ApplicationContext;
public class AaiClientPropertiesImpl implements AAIProperties {
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java
index 58a7cb2bff..f83e707258 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java
@@ -25,8 +25,8 @@ import java.net.URL;
import javax.ws.rs.core.MediaType;
-import org.onap.so.apihandlerinfra.SpringContextHelper;
import org.onap.so.client.grm.GRMProperties;
+import org.onap.so.spring.SpringContextHelper;
import org.springframework.context.ApplicationContext;
public class GrmClientPropertiesImpl implements GRMProperties {
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/dmaap/DmaapPropertiesImpl.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/dmaap/DmaapPropertiesImpl.java
index 0e26178e56..813299c370 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/dmaap/DmaapPropertiesImpl.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/dmaap/DmaapPropertiesImpl.java
@@ -23,8 +23,8 @@ package org.onap.so.apihandlerinfra.tenantisolation.dmaap;
import java.util.HashMap;
import java.util.Map;
-import org.onap.so.apihandlerinfra.SpringContextHelper;
import org.onap.so.client.dmaap.DmaapProperties;
+import org.onap.so.spring.SpringContextHelper;
import org.springframework.context.ApplicationContext;
public class DmaapPropertiesImpl implements DmaapProperties {
the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= */ package org.onap.policy.controlloop.common.rules.test; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; import java.util.concurrent.TimeUnit; import lombok.ToString; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicEndpoint; import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager; import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSink; import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSource; import org.onap.policy.common.endpoints.parameters.TopicParameters; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.protocol.coders.EventProtocolCoder; import org.onap.policy.drools.system.PolicyController; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; public class TopicsTest { private static final String EXPECTED_EXCEPTION = "expected exception"; private static final String MY_SOURCE_TOPIC = "my-source-topic"; private static final String MY_SINK_TOPIC = "my-sink-topic"; private static final String MY_GROUP = "my-group"; private static final String MY_ARTIFACT = "my-artifact"; private static final String MESSAGE = "{\"text\": \"hello\"}"; private static final String TEXT = "hello"; private static final String INJECT_FILE = "src/test/resources/topics.json"; private static final String POLICY_NAME = "my-policy"; @Mock private DroolsController drools; @Mock private PolicyController controller; @Mock private EventProtocolCoder protocolCoder; @Mock private NoopTopicSink sink; @Mock private NoopTopicSource source; @Mock private TopicEndpoint mgr; private ToscaPolicy policy; private Topics topics; /** * Creates topics. */ @BeforeClass public static void setUpBeforeClass() { TopicEndpointManager.getManager().shutdown(); TopicParameters params = new TopicParameters(); params.setTopic(MY_SOURCE_TOPIC); params.setManaged(true); params.setTopicCommInfrastructure("NOOP"); TopicEndpointManager.getManager().addTopicSources(List.of(params)); } @AfterClass public static void tearDownAfterClass() { TopicEndpointManager.getManager().shutdown(); } /** * Sets up. */ @Before public void setUp() { MockitoAnnotations.initMocks(this); policy = new ToscaPolicy(); policy.setName(POLICY_NAME); policy.setVersion("1.0.0"); when(drools.getGroupId()).thenReturn(MY_GROUP); when(drools.getArtifactId()).thenReturn(MY_ARTIFACT); when(controller.getDrools()).thenReturn(drools); when(protocolCoder.decode(MY_GROUP, MY_ARTIFACT, MY_SINK_TOPIC, MESSAGE)).thenReturn(TEXT); when(mgr.getNoopTopicSink(MY_SINK_TOPIC)).thenReturn(sink); when(mgr.getNoopTopicSource(MY_SOURCE_TOPIC)).thenReturn(source); topics = new Topics() { @Override protected TopicEndpoint getTopicManager() { return mgr; } @Override protected EventProtocolCoder getProtocolCoder() { return protocolCoder; } }; } @Test public void testDestroy() { Listener<String> listener1 = topics.createListener(MY_SINK_TOPIC, msg -> msg); Listener<String> listener2 = topics.createListener(MY_SINK_TOPIC, msg -> msg + "a suffix"); topics.destroy(); verify(sink).unregister(listener1); verify(sink).unregister(listener2); } @Test public void testInjectStringFile() throws IOException { topics.inject(MY_SOURCE_TOPIC, INJECT_FILE); // nothing should have been replaced String expected = new String(Files.readAllBytes(Paths.get(INJECT_FILE))); verify(source).offer(expected); } @Test public void testInjectStringFileString() throws IOException { topics.inject(MY_SOURCE_TOPIC, INJECT_FILE, "hello"); // text should have been replaced with "hello" String expected = new String(Files.readAllBytes(Paths.get("src", "test", "resources", "topicsReplaced.json"))); verify(source).offer(expected); // exception reading file assertThatThrownBy(() -> topics.inject(MY_SOURCE_TOPIC, "missing-file.json", "some text")) .isInstanceOf(TopicException.class); } @Test public void testCreateListenerStringClassOfTPolicyController() { Listener<String> listener = topics.createListener(MY_SINK_TOPIC, String.class, controller); listener.onTopicEvent(CommInfrastructure.NOOP, MY_SINK_TOPIC, MESSAGE); assertEquals(TEXT, listener.await()); } @Test public void testCreateListenerStringClassOfTCoder() { Listener<Data> listener = topics.createListener(MY_SINK_TOPIC, Data.class, new StandardCoder()); listener.onTopicEvent(CommInfrastructure.NOOP, MY_SINK_TOPIC, MESSAGE); Data expected = new Data(); expected.text = TEXT; assertEquals(expected.toString(), listener.await().toString()); } /** * Tests createListener() when the coder throws an exception. */ @Test public void testCreateListenerStringClassOfTCoderException() { StandardCoder coder = new StandardCoder() { @Override public <T> T decode(String arg0, Class<T> arg1) throws CoderException { throw new CoderException(EXPECTED_EXCEPTION); } }; Listener<Data> listener = topics.createListener(MY_SINK_TOPIC, Data.class, coder); // onTopicEvent() should not throw an exception assertThatCode(() -> listener.onTopicEvent(CommInfrastructure.NOOP, MY_SINK_TOPIC, MESSAGE)) .doesNotThrowAnyException(); // should not have queued a message assertThatThrownBy(() -> listener.await(0, TimeUnit.MILLISECONDS)).isInstanceOf(TopicException.class); } @Test public void testCreateListenerStringFunctionOfStringT() { Listener<String> listener = topics.createListener(MY_SINK_TOPIC, msg -> msg); listener.onTopicEvent(CommInfrastructure.NOOP, MY_SINK_TOPIC, MESSAGE); assertEquals(MESSAGE, listener.await()); } @Test public void testGetTopicManager_testGetProtocolCoder() { // use a topic with a real manager topics = new Topics(); assertNotNull(topics.getTopicManager()); assertNotNull(topics.getProtocolCoder()); } @ToString private static class Data { private String text; } }