summaryrefslogtreecommitdiffstats
path: root/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/onap/dcae/AccessControllerTest.java160
-rw-r--r--src/test/java/org/onap/dcae/ApplicationSettingsTest.java95
-rw-r--r--src/test/java/org/onap/dcae/CliUtilsTest.java (renamed from src/test/java/org/onap/dcae/CLIUtilsTest.java)5
-rw-r--r--src/test/java/org/onap/dcae/RestApiCallNodeUtilTest.java127
-rw-r--r--src/test/java/org/onap/dcae/TestingUtilities.java71
-rw-r--r--src/test/java/org/onap/dcae/TlsTest.java (renamed from src/test/java/org/onap/dcae/TLSTest.java)37
-rw-r--r--src/test/java/org/onap/dcae/TlsTestBase.java (renamed from src/test/java/org/onap/dcae/TLSTestBase.java)41
-rw-r--r--src/test/java/org/onap/dcae/WiremockBasedTest.java10
-rw-r--r--src/test/java/org/onap/dcae/common/AdditionalHeaderWebTargetTest.java60
-rw-r--r--src/test/java/org/onap/dcae/common/AuthTypeTest.java6
-rw-r--r--src/test/java/org/onap/dcae/common/DataChangeEventListnerTest.java18
-rw-r--r--src/test/java/org/onap/dcae/common/EventConnectionStateTest.java7
-rw-r--r--src/test/java/org/onap/dcae/common/EventProcessorTest.java157
-rw-r--r--src/test/java/org/onap/dcae/common/FormatTest.java5
-rw-r--r--src/test/java/org/onap/dcae/common/RestApiCallNodeTest.java197
-rw-r--r--src/test/java/org/onap/dcae/common/RestConfContextTest.java10
-rw-r--r--src/test/java/org/onap/dcae/common/XmlJsonUtilTest.java59
-rw-r--r--src/test/java/org/onap/dcae/common/XmlParserTest.java15
-rw-r--r--src/test/java/org/onap/dcae/common/publishing/DMaaPEventPublisherTest.java14
-rw-r--r--src/test/java/org/onap/dcae/common/publishing/DMaaPPublishersCacheTest.java61
-rw-r--r--src/test/java/org/onap/dcae/common/publishing/JsonParserTest.java28
-rw-r--r--src/test/java/org/onap/dcae/controller/ConfigCbsSourceTest.java (renamed from src/test/java/org/onap/dcae/controller/ConfigCBSSourceTest.java)22
-rw-r--r--src/test/java/org/onap/dcae/controller/ConfigFilesFacadeTest.java23
-rw-r--r--src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java88
-rw-r--r--src/test/java/org/onap/dcae/controller/ConfigParsingTest.java23
-rw-r--r--src/test/java/org/onap/dcae/controller/EnvPropertiesReaderTest.java5
-rw-r--r--src/test/java/org/onap/dcae/controller/EnvPropsTest.java15
-rw-r--r--src/test/java/org/onap/dcae/restapi/ApiAuthInterceptionTest.java20
28 files changed, 898 insertions, 481 deletions
diff --git a/src/test/java/org/onap/dcae/AccessControllerTest.java b/src/test/java/org/onap/dcae/AccessControllerTest.java
index 1e01340..4d66811 100644
--- a/src/test/java/org/onap/dcae/AccessControllerTest.java
+++ b/src/test/java/org/onap/dcae/AccessControllerTest.java
@@ -20,6 +20,16 @@
package org.onap.dcae;
+import static java.nio.file.Files.readAllBytes;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.ExecutorService;
+import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -28,17 +38,8 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.onap.dcae.common.RestConfContext;
import org.onap.dcae.common.RestapiCallNode;
import org.onap.dcae.controller.AccessController;
-
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.concurrent.ExecutorService;
-
-import org.json.JSONObject;
import org.onap.dcae.controller.PersistentEventConnection;
-import static java.nio.file.Files.readAllBytes;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.Silent.class)
public class AccessControllerTest {
@@ -49,8 +50,6 @@ public class AccessControllerTest {
@Mock
private RestConfContext ctx;
-
-
protected static final Path RESOURCES = Paths.get("src", "test", "resources");
protected static final Path KEYSTORE = Paths.get(RESOURCES.toString(), "keystore");
protected static final Path KEYSTORE_PASSWORD_FILE = Paths.get(RESOURCES.toString(), "passwordfile");
@@ -58,7 +57,7 @@ public class AccessControllerTest {
protected static final Path TRUSTSTORE_PASSWORD_FILE = Paths.get(RESOURCES.toString(), "trustpasswordfile");
protected static final Path RCC_KEYSTORE_PASSWORD_FILE = Paths.get(RESOURCES.toString(), "rcc_passwordfile");
protected static final Path RCC_KEYSTORE = Paths.get(RESOURCES.toString(), "sdnc.p12");
-
+ protected static final Path DMAAP_FILE = Paths.get(RESOURCES.toString(), "testDmaapConfig_ip.json");
@Test
public void createAndGetAccessControler() {
when(properties.truststoreFileLocation()).thenReturn(TRUSTSTORE.toString());
@@ -67,10 +66,20 @@ public class AccessControllerTest {
when(properties.keystorePasswordFileLocation()).thenReturn(KEYSTORE_PASSWORD_FILE.toString());
when(properties.rccKeystoreFileLocation()).thenReturn(RCC_KEYSTORE.toString());
when(properties.rccKeystorePasswordFileLocation()).thenReturn(RCC_KEYSTORE_PASSWORD_FILE.toString());
- try {
- when(readAllBytes(null)).thenReturn("colletor".getBytes());
- } catch (Exception e){}
- JSONObject controller = new JSONObject("{\"controller_name\":\"AccessM&C\",\"controller_restapiUrl\":\"10.118.191.43:26335\",\"controller_restapiUser\":\"access\",\"controller_restapiPassword\":\"Huawei@123\",\"controller_accessTokenUrl\":\"/rest/plat/smapp/v1/oauth/token\",\"controller_accessTokenFile\":\"./etc/access-token.json\",\"controller_accessTokenMethod\":\"put\",\"controller_subsMethod\":\"post\",\"controller_subscriptionUrl\":\"/restconf/v1/operations/huawei-nce-notification-action:establish-subscription\",\"controller_disableSsl\":\"true\",\"event_details\":[{\"event_name\":\"ONT_registration\",\"event_description\":\"ONTregistartionevent\",\"event_sseventUrlEmbed\":\"true\",\"event_sseventsField\":\"output.url\",\"event_sseventsUrl\":\"null\",\"event_subscriptionTemplate\":\"./etc/ont_registartion_subscription_template.json\",\"event_unSubscriptionTemplate\":\"./etc/ont_registartion_unsubscription_template.json\",\"event_ruleId\":\"777777777\"}]}");
+ when(properties.dMaaPConfigurationFileLocation()).thenReturn(DMAAP_FILE.toString());
+
+ JSONObject controller = new JSONObject("{\"controller_name\":\"AccessM&C\",\"controller_restapiUrl\":"
+ + "\"10.118.191.43:26335\",\"controller_restapiUser\":\"access\",\"controller_restapiPassword\":"
+ + "\"Huawei@123\",\"controller_accessTokenUrl\":\"/rest/plat/smapp/v1/oauth/token\","
+ + "\"controller_accessTokenFile\":\"./etc/access-token.json\",\"controller_accessTokenMethod\""
+ + ":\"put\",\"controller_subsMethod\":\"post\",\"controller_subscriptionUrl\":"
+ + "\"/restconf/v1/operations/huawei-nce-notification-action:establish-subscription\","
+ + "\"controller_disableSsl\":\"true\",\"event_details\":[{\"event_name\":\"ONT_registration\","
+ + "\"event_description\":\"ONTregistartionevent\",\"event_sseventUrlEmbed\":\"true\","
+ + "\"event_sseventsField\":\"output.url\",\"event_sseventsUrl\":\"null\","
+ + "\"event_subscriptionTemplate\":\"./etc/ont_registartion_subscription_template.json\","
+ + "\"event_unSubscriptionTemplate\":\"./etc/ont_registartion_unsubscription_template.json\","
+ + "\"event_ruleId\":\"777777777\"}]}");
try {
AccessController acClr = new AccessController(controller,
properties);
@@ -79,8 +88,11 @@ public class AccessControllerTest {
assertEquals(acClr.getCfgInfo().getController_name(), "AccessM&C");
assertEquals(acClr.getCfgInfo().getController_accessTokenMethod(), "put");
assertEquals(acClr.getCfgInfo().getController_subsMethod(), "post");
- assertEquals(acClr.getCfgInfo().getController_subscriptionUrl(), "/restconf/v1/operations/huawei-nce-notification-action:establish-subscription");
- } catch (Exception e){}
+ assertEquals(acClr.getCfgInfo().getController_subscriptionUrl(),
+ "/restconf/v1/operations/huawei-nce-notification-action:establish-subscription");
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
@Test
@@ -91,11 +103,95 @@ public class AccessControllerTest {
when(properties.keystorePasswordFileLocation()).thenReturn(KEYSTORE_PASSWORD_FILE.toString());
when(properties.rccKeystoreFileLocation()).thenReturn(RCC_KEYSTORE.toString());
when(properties.rccKeystorePasswordFileLocation()).thenReturn(RCC_KEYSTORE_PASSWORD_FILE.toString());
- when(properties.rccPolicy()).thenReturn("[{\"controller_name\":\"AccessM&C\",\"controller_restapiUrl\":\"10.118.191.43:26335\",\"controller_restapiUser\":\"access\",\"controller_restapiPassword\":\"Huawei@123\",\"controller_accessTokenUrl\":\"/rest/plat/smapp/v1/oauth/token\",\"controller_accessTokenFile\":\"./etc/access-token.json\",\"controller_accessTokenMethod\":\"put\",\"controller_subsMethod\":\"post\",\"controller_subscriptionUrl\":\"/restconf/v1/operations/huawei-nce-notification-action:establish-subscription\",\"controller_disableSsl\":\"true\",\"event_details\":[{\"event_name\":\"ONT_registration\",\"event_description\":\"ONTregistartionevent\",\"event_sseventUrlEmbed\":\"true\",\"event_sseventsField\":\"output.url\",\"event_sseventsUrl\":\"null\",\"event_subscriptionTemplate\":\"./etc/ont_registartion_subscription_template.json\",\"event_unSubscriptionTemplate\":\"./etc/ont_registartion_unsubscription_template.json\",\"event_ruleId\":\"777777777\"}]}]");
- when(ctx.getAttribute("responsePrefix.httpResponse")).thenReturn("{\"accessSession\" : \"1234567890\",\"result\" : \"Ok\"}");
+ when(properties.dMaaPConfigurationFileLocation()).thenReturn(DMAAP_FILE.toString());
+ when(properties.rccPolicy()).thenReturn("[{\"controller_name\":\"AccessM&C\","
+ + "\"controller_restapiUrl\":\"172.30.0.55:26335\","
+ + "\"controller_restapiUser\":\"access\",\"controller_restapiPassword\":"
+ + "\"Huawei@123\",\"controller_accessTokenUrl\":\"/rest/plat/smapp/v1/oauth/token\","
+ + "\"controller_accessTokenFile\":\"./etc/access-token.json\","
+ + "\"controller_accessTokenMethod\":\"put\",\"controller_subsMethod\":\"post\","
+ + "\"controller_subscriptionUrl\":\"/restconf/v1/operations/huawei-nce-notification-action:"
+ + "establish-subscription\",\"controller_disableSsl\":\"true\",\"event_details\":[{\"event_name"
+ + "\":\"ONT_registration\",\"event_description\":\"ONTregistartionevent\","
+ + "\"event_sseventUrlEmbed\":\"true\",\"event_sseventsField\":\"output.url\","
+ + "\"event_sseventsUrl\":\"null\",\"event_subscriptionTemplate\":"
+ + "\"./etc/ont_registartion_subscription_template.json\",\"event_unSubscriptionTemplate\":"
+ + "\"./etc/ont_registartion_unsubscription_template.json\",\"event_ruleId\":\"777777777\", "
+ + "\"modifyData\": \"true\", \"modifyMethod\": \"modifyOntEvent\", \"userData\": "
+ + "\"remote_id=AC9.0234.0337;svlan=100;cvlan=10;\"}]}]");
+ when(ctx.getAttribute("responsePrefix.httpResponse")).thenReturn("{\"accessSession\" : \"1234567890\","
+ + "\"result\" : \"Ok\"}");
+
+ try {
+
+ RestapiCallNode restApiCallNode = Mockito.mock(RestapiCallNode.class);
+ Mockito.doNothing().when(restApiCallNode).sendRequest(any(), any(), any());
+ ExecutorService executor = Mockito.mock(ExecutorService.class);
+ Mockito.doNothing().when(executor).execute(any());
+ PersistentEventConnection conn = mock(PersistentEventConnection.class);
+ Mockito.doNothing().when(conn).run();
+ when(properties.authorizationEnabled()).thenReturn(true);
+ JSONObject controller = new JSONObject("{\"controller_name\":\"AccessM&C\","
+ + "\"controller_restapiUrl\":\"10.118.191.43:26335\",\"controller_restapiUser\":\"access\","
+ + "\"controller_restapiPassword\":\"Huawei@123\",\"controller_accessTokenUrl\":"
+ + "\"/rest/plat/smapp/v1/oauth/token\",\"controller_accessTokenFile\":"
+ + "\"./etc/access-token.json\",\"controller_accessTokenMethod\":\"put\","
+ + "\"controller_subsMethod\":\"post\",\"controller_subscriptionUrl\":\""
+ + "/restconf/v1/operations/huawei-nce-notification-action:establish-subscription\","
+ + "\"controller_disableSsl\":\"true\",\"event_details\":[{\"event_name\":\"ONT_registration\","
+ + "\"event_description\":\"ONTregistartionevent\",\"event_sseventUrlEmbed\":\"true\","
+ + "\"event_sseventsField\":\"output.url\",\"event_sseventsUrl\":\"null\","
+ + "\"event_subscriptionTemplate\":\"./etc/ont_registartion_subscription_template.json\","
+ + "\"event_unSubscriptionTemplate\":\"./etc/ont_registartion_unsubscription_template.json\","
+ + "\"event_ruleId\":\"777777777\", \"modifyData\": \"true\"}]}");
+ AccessController acClr = new AccessController(controller,
+ properties);
+ AccessController acClr2 = new AccessController(controller,
+ properties);
+ acClr.equals(acClr2);
+ acClr.setRestApiCallNode(restApiCallNode);
+ //acClr.setExecutor(executor);
+ acClr.getCtx().setAttribute("responsePrefix.httpResponse",
+ "{\"accessSession\" : \"12dsaf4-2323-1231131232323\"}");
+ acClr.activate();
+ acClr.clearAllPersistentConnectios();
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
+ }
+
+ @Test
+ public void accessControllerSuccessfullyActivated2() {
+ when(properties.truststoreFileLocation()).thenReturn(TRUSTSTORE.toString());
+ when(properties.truststorePasswordFileLocation()).thenReturn(TRUSTSTORE_PASSWORD_FILE.toString());
+ when(properties.keystoreFileLocation()).thenReturn(KEYSTORE.toString());
+ when(properties.keystorePasswordFileLocation()).thenReturn(KEYSTORE_PASSWORD_FILE.toString());
+ when(properties.rccKeystoreFileLocation()).thenReturn(RCC_KEYSTORE.toString());
+ when(properties.rccKeystorePasswordFileLocation()).thenReturn(RCC_KEYSTORE_PASSWORD_FILE.toString());
+ when(properties.dMaaPConfigurationFileLocation()).thenReturn(DMAAP_FILE.toString());
+ when(properties.rccPolicy()).thenReturn("[{\"controller_name\":\"AccessM&C\","
+ + "\"controller_restapiUrl\":\"172.30.0.55:26335\","
+ + "\"controller_restapiUser\":\"access\",\"controller_restapiPassword\":"
+ + "\"Huawei@123\",\"controller_accessTokenUrl\":\"/rest/plat/smapp/v1/oauth/token\","
+ + "\"controller_accessTokenFile\":\"./etc/access-token.json\","
+ + "\"controller_accessTokenMethod\":\"put\",\"controller_subsMethod\":\"post\","
+ + "\"controller_subscriptionUrl\":\"/restconf/v1/operations/huawei-nce-notification-action:"
+ + "establish-subscription\",\"controller_disableSsl\":\"true\",\"event_details\":[{\"event_name"
+ + "\":\"ONT_registration\",\"event_description\":\"ONTregistartionevent\","
+ + "\"event_sseventUrlEmbed\":\"true\",\"event_sseventsField\":\"output.url\","
+ + "\"event_sseventsUrl\":\"null\",\"event_subscriptionTemplate\":"
+ + "\"./etc/ont_registartion_subscription_template.json\",\"event_unSubscriptionTemplate\":"
+ + "\"./etc/ont_registartion_unsubscription_template.json\",\"event_ruleId\":\"777777777\", "
+ + "\"modifyData\": \"true\", \"modifyMethod\": \"modifyOntEvent\", \"userData\": "
+ + "\"remote_id=AC9.0234.0337;svlan=100;cvlan=10;\"}]}]");
+ when(ctx.getAttribute("responsePrefix.httpResponse")).thenReturn("{\"accessSession\" : \"1234567890\","
+ + "\"result\" : \"Ok\"}");
try {
+ RestConfCollector.main(new String[]{"-c",
+ Paths.get("src/test/resources/testcollector.properties").toString()});
+
RestapiCallNode restApiCallNode = Mockito.mock(RestapiCallNode.class);
Mockito.doNothing().when(restApiCallNode).sendRequest(any(), any(), any());
ExecutorService executor = Mockito.mock(ExecutorService.class);
@@ -103,16 +199,32 @@ public class AccessControllerTest {
PersistentEventConnection conn = mock(PersistentEventConnection.class);
Mockito.doNothing().when(conn).run();
when(properties.authorizationEnabled()).thenReturn(true);
- JSONObject controller = new JSONObject("{\"controller_name\":\"AccessM&C\",\"controller_restapiUrl\":\"10.118.191.43:26335\",\"controller_restapiUser\":\"access\",\"controller_restapiPassword\":\"Huawei@123\",\"controller_accessTokenUrl\":\"/rest/plat/smapp/v1/oauth/token\",\"controller_accessTokenFile\":\"./etc/access-token.json\",\"controller_accessTokenMethod\":\"put\",\"controller_subsMethod\":\"post\",\"controller_subscriptionUrl\":\"/restconf/v1/operations/huawei-nce-notification-action:establish-subscription\",\"controller_disableSsl\":\"true\",\"event_details\":[{\"event_name\":\"ONT_registration\",\"event_description\":\"ONTregistartionevent\",\"event_sseventUrlEmbed\":\"true\",\"event_sseventsField\":\"output.url\",\"event_sseventsUrl\":\"null\",\"event_subscriptionTemplate\":\"./etc/ont_registartion_subscription_template.json\",\"event_unSubscriptionTemplate\":\"./etc/ont_registartion_unsubscription_template.json\",\"event_ruleId\":\"777777777\"}]}");
+ JSONObject controller = new JSONObject("{\"controller_name\":\"AccessM&C\","
+ + "\"controller_restapiUrl\":\"10.118.191.43:26335\",\"controller_restapiUser\":\"access\","
+ + "\"controller_restapiPassword\":\"Huawei@123\",\"controller_accessTokenUrl\":"
+ + "\"/rest/plat/smapp/v1/oauth/token\",\"controller_accessTokenFile\":"
+ + "\"./etc/access-token.json\",\"controller_accessTokenMethod\":\"put\","
+ + "\"controller_subsMethod\":\"post\",\"controller_subscriptionUrl\":\""
+ + "/restconf/v1/operations/huawei-nce-notification-action:establish-subscription\","
+ + "\"controller_disableSsl\":\"true\",\"event_details\":[{\"event_name\":\"ONT_registration\","
+ + "\"event_description\":\"ONTregistartionevent\",\"event_sseventUrlEmbed\":\"true\","
+ + "\"event_sseventsField\":\"output.url\",\"event_sseventsUrl\":\"null\","
+ + "\"event_subscriptionTemplate\":\"./etc/ont_registartion_subscription_template.json\","
+ + "\"event_unSubscriptionTemplate\":\"./etc/ont_registartion_unsubscription_template.json\","
+ + "\"event_ruleId\":\"777777777\", \"modifyData\": \"true\"}]}");
AccessController acClr = new AccessController(controller,
properties);
AccessController acClr2 = new AccessController(controller,
properties);
acClr.equals(acClr2);
acClr.setRestApiCallNode(restApiCallNode);
- acClr.setExecutor(executor);
- acClr.getCtx().setAttribute("responsePrefix.httpResponse","{\"accessSession\" : \"12dsaf4-2323-1231131232323\"}");
+ //acClr.setExecutor(executor);
+ acClr.getCtx().setAttribute("responsePrefix.httpResponse",
+ "{\"accessSession\" : \"12dsaf4-2323-1231131232323\"}");
acClr.activate();
- } catch (Exception e){}
+ acClr.clearAllPersistentConnectios();
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/ApplicationSettingsTest.java b/src/test/java/org/onap/dcae/ApplicationSettingsTest.java
index 3a9549f..d16953a 100644
--- a/src/test/java/org/onap/dcae/ApplicationSettingsTest.java
+++ b/src/test/java/org/onap/dcae/ApplicationSettingsTest.java
@@ -44,7 +44,7 @@ import org.junit.Test;
public class ApplicationSettingsTest {
@Test
- public void shouldMakeApplicationSettingsOutOfCLIArguments() {
+ public void shouldMakeApplicationSettingsOutOfCliArguments() {
// given
String[] cliArguments = {"-param1", "param1value", "-param2", "param2value"};
@@ -59,7 +59,7 @@ public class ApplicationSettingsTest {
}
@Test
- public void shouldMakeApplicationSettingsOutOfCLIArgumentsAndAConfigurationFile()
+ public void shouldMakeApplicationSettingsOutOfCliArgumentsAndAConfigurationFile()
throws IOException {
// given
File tempConfFile = File.createTempFile("doesNotMatter", "doesNotMatter");
@@ -71,18 +71,21 @@ public class ApplicationSettingsTest {
ApplicationSettings configurationAccessor = new ApplicationSettings(cliArguments, CLIUtils::processCmdLine);
String param1value = configurationAccessor.getStringDirectly("param1");
String param2value = configurationAccessor.getStringDirectly("param2");
- String fromFileParam1Value = configurationAccessor.getStringDirectly("section.subSection1");
- String fromFileParam2Value = configurationAccessor.getStringDirectly("section.subSection2");
// then
assertEquals("param1value", param1value);
assertEquals("param2value", param2value);
+
+ String fromFileParam1Value = configurationAccessor.getStringDirectly("section.subSection1");
+ String fromFileParam2Value = configurationAccessor.getStringDirectly("section.subSection2");
+
+ // then
assertEquals("abc", fromFileParam1Value);
assertEquals("zxc", fromFileParam2Value);
}
@Test
- public void shouldCLIArgumentsOverrideConfigFileParameters() throws IOException {
+ public void shouldCliArgumentsOverrideConfigFileParameters() throws IOException {
// given
String[] cliArguments = {"-section.subSection1", "abc"};
File tempConfFile = File.createTempFile("doesNotMatter", "doesNotMatter");
@@ -91,20 +94,19 @@ public class ApplicationSettingsTest {
// when
ApplicationSettings configurationAccessor = new ApplicationSettings(cliArguments, CLIUtils::processCmdLine);
- String actuallyOverridenByCLIParam = configurationAccessor.getStringDirectly("section.subSection1");
+ String actuallyOverridenByCliParam = configurationAccessor.getStringDirectly("section.subSection1");
// then
- assertEquals("abc", actuallyOverridenByCLIParam);
+ assertEquals("abc", actuallyOverridenByCliParam);
configurationAccessor.reloadProperties();
- Path p = configurationAccessor.configurationFileLocation();
boolean auth = configurationAccessor.clientTlsAuthenticationEnabled();
assertEquals(auth, false);
}
@Test
- public void shouldReturnHTTPPort() throws IOException {
+ public void shouldReturnHttpPort() throws IOException {
// when
int applicationPort = fromTemporaryConfiguration("collector.rcc.service.port=8090")
.httpPort();
@@ -114,7 +116,7 @@ public class ApplicationSettingsTest {
}
@Test
- public void shouldReturnDefaultHTTPPort() throws IOException {
+ public void shouldReturnDefaultHttpPort() throws IOException {
// when
int applicationPort = fromTemporaryConfiguration().httpPort();
@@ -123,7 +125,7 @@ public class ApplicationSettingsTest {
}
@Test
- public void shouldReturnIfHTTPSIsEnabled() throws IOException {
+ public void shouldReturnIfHttpSIsEnabled() throws IOException {
// when
boolean httpsEnabled = fromTemporaryConfiguration("collector.rcc.service.secure.port=8687")
.httpsEnabled();
@@ -133,7 +135,7 @@ public class ApplicationSettingsTest {
}
@Test
- public void shouldReturnIfHTTPIsEnabled() throws IOException {
+ public void shouldReturnIfHttpIsEnabled() throws IOException {
// when
boolean httpsEnabled = fromTemporaryConfiguration("collector.service.port=8080").httpsEnabled();
// then
@@ -141,7 +143,7 @@ public class ApplicationSettingsTest {
}
@Test
- public void shouldByDefaultHTTPSBeDisabled() throws IOException {
+ public void shouldByDefaultHttpSBeDisabled() throws IOException {
// when
boolean httpsEnabled = fromTemporaryConfiguration().httpsEnabled();
@@ -150,7 +152,7 @@ public class ApplicationSettingsTest {
}
@Test
- public void shouldReturnHTTPSPort() throws IOException {
+ public void shouldReturnHttpSPort() throws IOException {
// when
int httpsPort = fromTemporaryConfiguration("collector.service.secure.port=8687")
.httpsPort();
@@ -163,7 +165,8 @@ public class ApplicationSettingsTest {
@Test
public void shouldReturnLocationOfThePasswordFile() throws IOException {
// when
- String passwordFileLocation = fromTemporaryConfiguration("collector.rcc.keystore.passwordfile=/somewhere/password")
+ String passwordFileLocation = fromTemporaryConfiguration(
+ "collector.rcc.keystore.passwordfile=/somewhere/password")
.keystorePasswordFileLocation();
// then
@@ -182,7 +185,8 @@ public class ApplicationSettingsTest {
@Test
public void shouldReturnLocationOfTheKeystoreFile() throws IOException {
// when
- String keystoreFileLocation = fromTemporaryConfiguration("collector.rcc.keystore.file.location=/somewhere/keystore")
+ String keystoreFileLocation = fromTemporaryConfiguration(
+ "collector.rcc.keystore.file.location=/somewhere/keystore")
.keystoreFileLocation();
// then
@@ -199,9 +203,10 @@ public class ApplicationSettingsTest {
}
@Test
- public void shouldReturnDMAAPConfigFileLocation() throws IOException {
+ public void shouldReturnDmaapConfigFileLocation() throws IOException {
// when
- String dmaapConfigFileLocation = fromTemporaryConfiguration("collector.dmaapfile=/somewhere/dmaapFile")
+ String dmaapConfigFileLocation = fromTemporaryConfiguration(
+ "collector.dmaapfile=/somewhere/dmaapFile")
.dMaaPConfigurationFileLocation();
// then
@@ -209,7 +214,7 @@ public class ApplicationSettingsTest {
}
@Test
- public void shouldReturnDefaultDMAAPConfigFileLocation() throws IOException {
+ public void shouldReturnDefaultDmaapConfigFileLocation() throws IOException {
// when
String dmaapConfigFileLocation = fromTemporaryConfiguration().dMaaPConfigurationFileLocation();
@@ -220,7 +225,8 @@ public class ApplicationSettingsTest {
@Test
public void shouldReturnMaximumAllowedQueuedEvents() throws IOException {
// when
- int maximumAllowedQueuedEvents = fromTemporaryConfiguration("collector.rcc.inputQueue.maxPending=10000")
+ int maximumAllowedQueuedEvents = fromTemporaryConfiguration(
+ "collector.rcc.inputQueue.maxPending=10000")
.maximumAllowedQueuedEvents();
// then
@@ -236,37 +242,6 @@ public class ApplicationSettingsTest {
assertEquals(1024 * 4, maximumAllowedQueuedEvents);
}
-
-
-
-// @Test
-// public void shouldReturnDMAAPStreamId() throws IOException {
-// // given
-// Map<String, String[]> expected = HashMap.of(
-// "s", new String[]{"something", "something2"},
-// "s2", new String[]{"something3"}
-// );
-//
-// // when
-// Map<String, String[]> dmaapStreamID = fromTemporaryConfiguration(
-// "collector.dmaap.streamid=s=something,something2|s2=something3")
-// .dMaaPStreamsMapping();
-//
-// // then
-// assertArrayEquals(expected.get("s").get(), Objects.requireNonNull(dmaapStreamID).get("s").get());
-// assertArrayEquals(expected.get("s2").get(), Objects.requireNonNull(dmaapStreamID).get("s2").get());
-// assertEquals(expected.keySet(), dmaapStreamID.keySet());
-// }
-//
-// @Test
-// public void shouldReturnDefaultDMAAPStreamId() throws IOException {
-// // when
-// Map<String, String[]> dmaapStreamID = fromTemporaryConfiguration().dMaaPStreamsMapping();
-//
-// // then
-// assertEquals(dmaapStreamID, HashMap.empty());
-// }
-
@Test
public void shouldReturnIfAuthorizationIsEnabled() throws IOException {
// when
@@ -301,8 +276,8 @@ public class ApplicationSettingsTest {
@Test
public void shouldbyDefaultThereShouldBeNoValidCredentials() throws IOException {
// when
- Map<String, String> userToBase64PasswordDelimitedByCommaSeparatedByPipes = fromTemporaryConfiguration().
- validAuthorizationCredentials();
+ Map<String, String> userToBase64PasswordDelimitedByCommaSeparatedByPipes = fromTemporaryConfiguration()
+ .validAuthorizationCredentials();
// then
assertTrue(userToBase64PasswordDelimitedByCommaSeparatedByPipes.isEmpty());
@@ -333,7 +308,7 @@ public class ApplicationSettingsTest {
@Test
public void shouldrccKeystorePathExistDefault() throws IOException {
// when
- String path= fromTemporaryConfiguration().rccKeystoreFileLocation();
+ String path = fromTemporaryConfiguration().rccKeystoreFileLocation();
// then
assertEquals(sanitizePath("etc/keystore"), path);
@@ -342,7 +317,7 @@ public class ApplicationSettingsTest {
@Test
public void shouldrccKeystorePasswordExistDefault() throws IOException {
// when
- String path= fromTemporaryConfiguration().rccKeystorePasswordFileLocation();
+ String path = fromTemporaryConfiguration().rccKeystorePasswordFileLocation();
// then
assertEquals(sanitizePath("etc/rcc_passwordfile"), path);
@@ -351,7 +326,7 @@ public class ApplicationSettingsTest {
@Test
public void shouldTruststorePathExistDefault() throws IOException {
// when
- String path= fromTemporaryConfiguration().truststorePasswordFileLocation();
+ String path = fromTemporaryConfiguration().truststorePasswordFileLocation();
// then
assertEquals(sanitizePath("etc/trustpasswordfile"), path);
@@ -360,7 +335,7 @@ public class ApplicationSettingsTest {
@Test
public void shouldTruststorePasswordExistDefault() throws IOException {
// when
- String path= fromTemporaryConfiguration().truststoreFileLocation();
+ String path = fromTemporaryConfiguration().truststoreFileLocation();
// then
assertEquals(sanitizePath("etc/truststore.onap.client.jks"), path);
@@ -392,12 +367,16 @@ public class ApplicationSettingsTest {
// then
assertEquals(stream, null);
}
+
private static ApplicationSettings fromTemporaryConfiguration(String... fileLines)
throws IOException {
File tempConfFile = File.createTempFile("doesNotMatter", "doesNotMatter");
Files.write(tempConfFile.toPath(), Arrays.asList(fileLines));
tempConfFile.deleteOnExit();
- return new ApplicationSettings(new String[]{"-c", tempConfFile.toString()}, args -> processCmdLine(args), "");
+ return new ApplicationSettings(
+ new String[]{"-c", tempConfFile.toString()},
+ args -> processCmdLine(args),
+ "");
}
private String sanitizePath(String path) {
diff --git a/src/test/java/org/onap/dcae/CLIUtilsTest.java b/src/test/java/org/onap/dcae/CliUtilsTest.java
index caf88ac..66d3f9b 100644
--- a/src/test/java/org/onap/dcae/CLIUtilsTest.java
+++ b/src/test/java/org/onap/dcae/CliUtilsTest.java
@@ -22,12 +22,13 @@
package org.onap.dcae;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.vavr.collection.Map;
import org.junit.Test;
-import static org.assertj.core.api.Assertions.assertThat;
-public class CLIUtilsTest {
+public class CliUtilsTest {
@Test
public void shouldConvertArgsToPropertiesMap() {
diff --git a/src/test/java/org/onap/dcae/RestApiCallNodeUtilTest.java b/src/test/java/org/onap/dcae/RestApiCallNodeUtilTest.java
index 723ffea..477975c 100644
--- a/src/test/java/org/onap/dcae/RestApiCallNodeUtilTest.java
+++ b/src/test/java/org/onap/dcae/RestApiCallNodeUtilTest.java
@@ -20,17 +20,20 @@
package org.onap.dcae;
-import org.junit.Test;
-import org.onap.dcae.common.*;
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
-import java.util.*;
-import java.util.Map;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import org.junit.Test;
+import org.onap.dcae.common.AuthType;
+import org.onap.dcae.common.Constants;
+import org.onap.dcae.common.Parameters;
+import org.onap.dcae.common.RestapiCallNodeUtil;
+
/**
* Created by koblosz on 07.06.18.
@@ -69,12 +72,14 @@ public class RestApiCallNodeUtilTest {
String trustPassword = "admin";
paraMap.put(Constants.KSETTING_TRUST_STORE_PASSWORD, trustPassword);
paraMap.put(Constants.KSETTING_KEY_STORE_FILENAME, null);
- String KeyPassword = "admin";
- paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, KeyPassword);
+ String keyPassword = "admin";
+ paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, keyPassword);
try {
- Parameters p = RestapiCallNodeUtil.getParameters(paraMap);
- assertEquals(p.contentType, "application/json");
- } catch (Exception e) {}
+ Parameters parameters = RestapiCallNodeUtil.getParameters(paraMap);
+ assertEquals(parameters.contentType, "application/json");
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
@@ -82,7 +87,11 @@ public class RestApiCallNodeUtilTest {
public void parseComplexParam() {
Map<String, String> paraMap = new HashMap<>();
paraMap.put(Constants.KDEFAULT_TEMP_FILENAME, null);
- paraMap.put(Constants.KSETTING_REST_API_URL, "https://sonar.onap.org/component_measures?id=org.onap.dcaegen2.collectors.restconf%3Arestconfcollector&metric=coverage&selected=org.onap.dcaegen2.collectors.restconf%3Arestconfcollector%3Asrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdcae%2Fcommon%2FRestapiCallNodeUtil.java");
+ paraMap.put(Constants.KSETTING_REST_API_URL,
+ "https://sonar.onap.org/component_measures?id=org.onap.dcaegen2.collectors."
+ + "restconf%3Arestconfcollector&metric=coverage&selected=org.onap.dcaegen2.collectors"
+ + ".restconf%3Arestconfcollector%3Asrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdcae%2Fcommon%2F"
+ + "RestapiCallNodeUtil.java");
paraMap.put(Constants.KSETTING_HTTP_METHOD, "post");
paraMap.put(Constants.KSETTING_RESP_PREFIX, "responsePrefix");
paraMap.put(Constants.KSETTING_SKIP_SENDING, "false");
@@ -109,21 +118,25 @@ public class RestApiCallNodeUtilTest {
String trustPassword = "admin";
paraMap.put(Constants.KSETTING_TRUST_STORE_PASSWORD, trustPassword);
paraMap.put(Constants.KSETTING_KEY_STORE_FILENAME, null);
- String KeyPassword = "admin";
- paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, KeyPassword);
+ String keyPassword = "admin";
+ paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, keyPassword);
try {
- Parameters p = RestapiCallNodeUtil.getParameters(paraMap);
- assertEquals(p.contentType, "application/json");
- } catch (Exception e) {}
+ Parameters parameters = RestapiCallNodeUtil.getParameters(paraMap);
+ assertEquals(parameters.contentType, "application/json");
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
@Test
public void parseinValidUrl() {
Map<String, String> paraMap = new HashMap<>();
- paraMap.put(Constants.KSETTING_REST_API_URL, "");
+ paraMap.put(Constants.KSETTING_REST_API_URL, "$$$");
try {
- Parameters p = RestapiCallNodeUtil.getParameters(paraMap);
- } catch (Exception e) {}
+ Parameters parameters = RestapiCallNodeUtil.getParameters(paraMap);
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
@Test
@@ -158,47 +171,53 @@ public class RestApiCallNodeUtilTest {
String trustPassword = "admin";
paraMap.put(Constants.KSETTING_TRUST_STORE_PASSWORD, trustPassword);
paraMap.put(Constants.KSETTING_KEY_STORE_FILENAME, null);
- String KeyPassword = "admin";
- paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, KeyPassword);
+ String keyPassword = "admin";
+ paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, keyPassword);
Client client = ClientBuilder.newBuilder().build();
try {
- Parameters p = RestapiCallNodeUtil.getParameters(paraMap);
- p.restapiUser = "restapiUser";
- p.restapiPassword = "restapiPassword";
- RestapiCallNodeUtil.addAuthType(client, p);
-
- p.restapiUser = null;
- p.restapiPassword = null;
- p.oAuthConsumerKey = "restapiUser";
- p.oAuthSignatureMethod = "restapiPassword";
- p.oAuthConsumerSecret = "someval";
- RestapiCallNodeUtil.addAuthType(client, p);
-
- p.authtype = AuthType.DIGEST;
- p.restapiUser = "restapiUser";
- p.restapiPassword = "restapiPassword";
- RestapiCallNodeUtil.addAuthType(client, p);
- } catch (Exception e) {}
+ Parameters parameters = RestapiCallNodeUtil.getParameters(paraMap);
+ parameters.restapiUser = "restapiUser";
+ parameters.restapiPassword = "restapiPassword";
+ RestapiCallNodeUtil.addAuthType(client, parameters);
+
+ parameters.restapiUser = null;
+ parameters.restapiPassword = null;
+ parameters.oAuthConsumerKey = "restapiUser";
+ parameters.oAuthSignatureMethod = "restapiPassword";
+ parameters.oAuthConsumerSecret = "someval";
+ RestapiCallNodeUtil.addAuthType(client, parameters);
+
+ parameters.authtype = AuthType.DIGEST;
+ parameters.restapiUser = "restapiUser";
+ parameters.restapiPassword = "restapiPassword";
+ RestapiCallNodeUtil.addAuthType(client, parameters);
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
try {
- Parameters p = RestapiCallNodeUtil.getParameters(paraMap);
- p.authtype = AuthType.BASIC;
- p.restapiUser = "restapiUser";
- p.restapiPassword = "restapiPassword";
- RestapiCallNodeUtil.addAuthType(client, p);
+ Parameters parameters = RestapiCallNodeUtil.getParameters(paraMap);
+ parameters.authtype = AuthType.BASIC;
+ parameters.restapiUser = "restapiUser";
+ parameters.restapiPassword = "restapiPassword";
+ RestapiCallNodeUtil.addAuthType(client, parameters);
- } catch (Exception e) {}
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
try {
- Parameters p = RestapiCallNodeUtil.getParameters(paraMap);
- p.authtype = AuthType.OAUTH;
- p.oAuthConsumerKey = "restapiUser";
- p.oAuthSignatureMethod = "restapiPassword";
- p.oAuthConsumerSecret = "someval";
- RestapiCallNodeUtil.addAuthType(client, p);
-
- } catch (Exception e) {}
+ Parameters parameters = RestapiCallNodeUtil.getParameters(paraMap);
+ parameters.authtype = AuthType.OAUTH;
+ parameters.oAuthConsumerKey = "restapiUser";
+ parameters.oAuthSignatureMethod = "restapiPassword";
+ parameters.oAuthConsumerSecret = "someval";
+ RestapiCallNodeUtil.addAuthType(client, parameters);
+
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/TestingUtilities.java b/src/test/java/org/onap/dcae/TestingUtilities.java
index 5ae238a..14c34c9 100644
--- a/src/test/java/org/onap/dcae/TestingUtilities.java
+++ b/src/test/java/org/onap/dcae/TestingUtilities.java
@@ -19,25 +19,20 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae;
import static java.nio.file.Files.readAllBytes;
import static org.assertj.core.api.Assertions.assertThat;
import io.vavr.control.Try;
-
import java.io.File;
import java.io.FileInputStream;
-import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateException;
-
+import javax.net.ssl.SSLContext;
import org.apache.http.client.HttpClient;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.HttpClients;
@@ -48,7 +43,7 @@ import org.json.JSONObject;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
-import javax.net.ssl.SSLContext;
+
public final class TestingUtilities {
@@ -56,21 +51,41 @@ public final class TestingUtilities {
// utility class, no objects allowed
}
- public static void assertJSONObjectsEqual(JSONObject o1, JSONObject o2) {
+ /**
+ * Assert if JSON Objects are Equal.
+ * @param o1 JSONObject one.
+ * @param o2 JSONObject two.
+ */
+ public static void assertJsonObjectsEqual(JSONObject o1, JSONObject o2) {
assertThat(o1.toString()).isEqualTo(o2.toString());
}
- public static JSONObject readJSONFromFile(Path path) {
+ /**
+ * Read JSON From File.
+ * @param path path of file.
+ * @return JSON Object.
+ */
+ public static JSONObject readJsonFromFile(Path path) {
return rethrow(() -> new JSONObject(readFile(path)));
}
+ /**
+ * Read File from givn path.
+ * @param path path of file.
+ * @return String content.
+ */
public static String readFile(Path path) {
return rethrow(() -> new String(readAllBytes(path)));
}
- public static Path createTemporaryFile(String content) {
+ /**
+ * Create Temporary File.
+ * @param content content of file.
+ * @return Path.
+ */
+ public static Path createTemporaryFile(String name, String content) {
return rethrow(() -> {
- File temp = File.createTempFile("restconf-collector-tests-created-this-file", ".tmp");
+ File temp = File.createTempFile(name, ".tmp");
temp.deleteOnExit();
Path filePath = Paths.get(temp.toString());
Files.write(filePath, content.getBytes());
@@ -82,6 +97,7 @@ public final class TestingUtilities {
* Exception in test case usually means there is something wrong, it should never be catched, but rather thrown to
* be handled by JUnit framework.
*/
+
public static <T> T rethrow(CheckedSupplier<T> supplier) {
try {
return supplier.get();
@@ -90,21 +106,36 @@ public final class TestingUtilities {
}
}
+ /**
+ *
+ * @param <T> .
+ */
@FunctionalInterface
interface CheckedSupplier<T> {
T get() throws Exception;
}
+ /** Assert if Failure Has Info.
+ *
+ * @param any any object
+ * @param msgPart msg part
+ */
public static void assertFailureHasInfo(Try any, String... msgPart) {
Java6Assertions.assertThat(any.isFailure()).isTrue();
- AbstractThrowableAssert<?, ? extends Throwable> o = Java6Assertions.assertThat(any.getCause())
+ AbstractThrowableAssert<?, ? extends Throwable> instance = Java6Assertions.assertThat(any.getCause())
.hasCauseInstanceOf(Exception.class);
for (String s : msgPart) {
- o.hasStackTraceContaining(s);
+ instance.hasStackTraceContaining(s);
}
}
+ /**
+ * SSL Builder With TrustStore.
+ * @param trustStore path of file.
+ * @param pass password.
+ * @return SSLContextBuilder.
+ */
public static SSLContextBuilder sslBuilderWithTrustStore(final Path trustStore, final String pass) {
return rethrow(() ->
new SSLContextBuilder()
@@ -112,6 +143,13 @@ public final class TestingUtilities {
);
}
+ /**
+ * Configure Key Store for testing.
+ * @param builder class builder.
+ * @param keyStore path of file.
+ * @param pass password.
+ * @return SSLContextBuilder.
+ */
public static SSLContextBuilder configureKeyStore(
final SSLContextBuilder builder,
final Path keyStore,
@@ -126,6 +164,11 @@ public final class TestingUtilities {
});
}
+ /**
+ * Create Rest Template With Ssl.
+ * @param context ssl context
+ * @return RestTemplate
+ */
public static RestTemplate createRestTemplateWithSsl(final SSLContext context) {
final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(context);
final HttpClient httpClient = HttpClients
diff --git a/src/test/java/org/onap/dcae/TLSTest.java b/src/test/java/org/onap/dcae/TlsTest.java
index 37505d3..a141985 100644
--- a/src/test/java/org/onap/dcae/TLSTest.java
+++ b/src/test/java/org/onap/dcae/TlsTest.java
@@ -22,19 +22,20 @@
package org.onap.dcae;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.when;
+import static org.onap.dcae.TlsTest.HttpsConfiguration.PASSWORD;
+import static org.onap.dcae.TlsTest.HttpsConfiguration.USERNAME;
+
import io.vavr.collection.HashMap;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
import org.springframework.http.HttpStatus;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.Mockito.when;
-import static org.onap.dcae.TLSTest.HttpsConfiguration.PASSWORD;
-import static org.onap.dcae.TLSTest.HttpsConfiguration.USERNAME;
-
-public class TLSTest extends TLSTestBase {
+public class TlsTest extends TlsTestBase {
@Nested
@Import(HttpConfiguration.class)
@@ -68,8 +69,8 @@ public class TLSTest extends TLSTestBase {
}
@Nested
- @Import(HttpsConfigurationWithTLSAuthentication.class)
- class HttpsWithTLSAuthenticationTest extends TestClassBase {
+ @Import(HttpsConfigurationWithTlsAuthentication.class)
+ class HttpsWithTlsAuthenticationTest extends TestClassBase {
@Test
public void shouldHttpsRequestWithoutCertificateFail() {
@@ -78,8 +79,8 @@ public class TLSTest extends TLSTestBase {
}
@Nested
- @Import(HttpsConfigurationWithTLSAuthenticationAndBasicAuth.class)
- class HttpsWithTLSAuthenticationAndBasicAuthTest extends TestClassBase {
+ @Import(HttpsConfigurationWithTlsAuthenticationAndBasicAuth.class)
+ class HttpsWithTlsAuthenticationAndBasicAuthTest extends TestClassBase {
@Test
public void shouldHttpsRequestWithoutBasicAuthFail() {
@@ -88,17 +89,18 @@ public class TLSTest extends TLSTestBase {
@Test
public void shouldHttpsRequestWithBasicAuthSucceed() {
- assertEquals(HttpStatus.OK, makeHttpsRequestWithClientCertAndBasicAuth(USERNAME, PASSWORD).getStatusCode());
+ assertEquals(HttpStatus.OK,
+ makeHttpsRequestWithClientCertAndBasicAuth(USERNAME, PASSWORD).getStatusCode());
}
}
- static class HttpConfiguration extends TLSTestBase.ConfigurationBase {
+ static class HttpConfiguration extends TlsTestBase.ConfigurationBase {
@Override
protected void configureSettings(ApplicationSettings settings) {
}
}
- static class HttpsConfiguration extends TLSTestBase.ConfigurationBase {
+ static class HttpsConfiguration extends TlsTestBase.ConfigurationBase {
public static final String USERNAME = "TestUser";
public static final String PASSWORD = "TestPassword";
@@ -109,11 +111,12 @@ public class TLSTest extends TLSTestBase {
when(settings.rccKeystoreFileLocation()).thenReturn(RCC_KEYSTORE.toString());
when(settings.rccKeystorePasswordFileLocation()).thenReturn(RCC_KEYSTORE_PASSWORD_FILE.toString());
when(settings.authorizationEnabled()).thenReturn(true);
- when(settings.validAuthorizationCredentials()).thenReturn(HashMap.of(USERNAME, "$2a$10$51tDgG2VNLde5E173Ay/YO.Fq.aD.LR2Rp8pY3QAKriOSPswvGviy"));
+ when(settings.validAuthorizationCredentials()).thenReturn(HashMap.of(USERNAME,
+ "$2a$10$51tDgG2VNLde5E173Ay/YO.Fq.aD.LR2Rp8pY3QAKriOSPswvGviy"));
}
}
- static class HttpsConfigurationWithTLSAuthentication extends HttpsConfiguration {
+ static class HttpsConfigurationWithTlsAuthentication extends HttpsConfiguration {
@Override
protected void configureSettings(ApplicationSettings settings) {
super.configureSettings(settings);
@@ -125,7 +128,7 @@ public class TLSTest extends TLSTestBase {
}
}
- static class HttpsConfigurationWithTLSAuthenticationAndBasicAuth extends HttpsConfigurationWithTLSAuthentication {
+ static class HttpsConfigurationWithTlsAuthenticationAndBasicAuth extends HttpsConfigurationWithTlsAuthentication {
@Override
protected void configureSettings(ApplicationSettings settings) {
super.configureSettings(settings);
diff --git a/src/test/java/org/onap/dcae/TLSTestBase.java b/src/test/java/org/onap/dcae/TlsTestBase.java
index a35f009..708b3bd 100644
--- a/src/test/java/org/onap/dcae/TLSTestBase.java
+++ b/src/test/java/org/onap/dcae/TlsTestBase.java
@@ -19,8 +19,19 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae;
+import static org.onap.dcae.TestingUtilities.configureKeyStore;
+import static org.onap.dcae.TestingUtilities.createRestTemplateWithSsl;
+import static org.onap.dcae.TestingUtilities.readFile;
+import static org.onap.dcae.TestingUtilities.rethrow;
+import static org.onap.dcae.TestingUtilities.sslBuilderWithTrustStore;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.LinkedBlockingQueue;
+
import org.json.JSONObject;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
@@ -36,15 +47,13 @@ import org.springframework.http.client.support.BasicAuthenticationInterceptor;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.web.client.RestTemplate;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.concurrent.LinkedBlockingQueue;
-import static org.onap.dcae.TestingUtilities.*;
+
+
@Configuration
@ExtendWith(SpringExtension.class)
-public class TLSTestBase {
+public class TlsTestBase {
protected static final String KEYSTORE_ALIAS = "tomcat";
protected static final Path RESOURCES = Paths.get("src", "test", "resources");
protected static final Path KEYSTORE = Paths.get(RESOURCES.toString(), "keystore");
@@ -54,7 +63,7 @@ public class TLSTestBase {
protected static final Path RCC_KEYSTORE_PASSWORD_FILE = Paths.get(RESOURCES.toString(), "passwordfile");
protected static final Path RCC_KEYSTORE = Paths.get(RESOURCES.toString(), "keystore");
- protected static abstract class ConfigurationBase {
+ protected abstract static class ConfigurationBase {
protected final ApplicationSettings settings = Mockito.mock(ApplicationSettings.class);
@Bean
@@ -84,7 +93,7 @@ public class TLSTestBase {
trustStorePassword = readFile(TRUSTSTORE_PASSWORD_FILE);
}
- private String getURL(final String protocol, final String uri) {
+ private String getUrl(final String protocol, final String uri) {
return protocol + "://localhost:" + port + uri;
}
@@ -95,12 +104,12 @@ public class TLSTestBase {
return template;
}
- public String createHttpURL(String uri) {
- return getURL("http", uri);
+ public String createHttpUrl(String uri) {
+ return getUrl("http", uri);
}
- public String createHttpsURL(String uri) {
- return getURL("https", uri);
+ public String createHttpsUrl(String uri) {
+ return getUrl("https", uri);
}
public RestTemplate createHttpRestTemplate() {
@@ -126,29 +135,29 @@ public class TLSTestBase {
}
public ResponseEntity<String> makeHttpRequest() {
- return createHttpRestTemplate().getForEntity(createHttpURL("/"), String.class);
+ return createHttpRestTemplate().getForEntity(createHttpUrl("/"), String.class);
}
public ResponseEntity<String> makeHttpsRequest() {
- return createHttpsRestTemplate().getForEntity(createHttpsURL("/"), String.class);
+ return createHttpsRestTemplate().getForEntity(createHttpsUrl("/"), String.class);
}
public ResponseEntity<String> makeHttpsRequestWithBasicAuth(final String username, final String password) {
return addBasicAuth(createHttpsRestTemplate(), username, password)
- .getForEntity(createHttpsURL("/"), String.class);
+ .getForEntity(createHttpsUrl("/"), String.class);
}
public ResponseEntity<String> makeHttpsRequestWithClientCert() {
- return createHttpsRestTemplateWithKeyStore().getForEntity(createHttpsURL("/"), String.class);
+ return createHttpsRestTemplateWithKeyStore().getForEntity(createHttpsUrl("/"), String.class);
}
public ResponseEntity<String> makeHttpsRequestWithClientCertAndBasicAuth(
final String username,
final String password) {
return addBasicAuth(createHttpsRestTemplateWithKeyStore(), username, password)
- .getForEntity(createHttpsURL("/"), String.class);
+ .getForEntity(createHttpsUrl("/"), String.class);
}
}
}
diff --git a/src/test/java/org/onap/dcae/WiremockBasedTest.java b/src/test/java/org/onap/dcae/WiremockBasedTest.java
index 2144e99..da1ee1d 100644
--- a/src/test/java/org/onap/dcae/WiremockBasedTest.java
+++ b/src/test/java/org/onap/dcae/WiremockBasedTest.java
@@ -39,14 +39,14 @@ public class WiremockBasedTest {
public WireMockRule wireMockRule = new WireMockRule(
wireMockConfig().dynamicPort().dynamicHttpsPort().keystorePath(null));
- protected void stubConsulToReturnLocalAddressOfCBS() {
+ protected void stubConsulToReturnLocalAddressOfCbs() {
stubFor(get(urlEqualTo("/v1/catalog/service/CBSName"))
- .willReturn(aResponse().withBody(validLocalCBSConf())));
+ .willReturn(aResponse().withBody(validLocalCbsConf())));
}
- protected void stubCBSToReturnAppConfig(String sampleConfigForVES) {
+ protected void stubCbsToReturnAppConfig(String sampleConfigForVes) {
stubFor(get(urlEqualTo("/service_component/restconfcollector"))
- .willReturn(aResponse().withBody(sampleConfigForVES)));
+ .willReturn(aResponse().withBody(sampleConfigForVes)));
}
protected Map<String, String> wiremockBasedEnvProps() {
@@ -58,7 +58,7 @@ public class WiremockBasedTest {
);
}
- protected String validLocalCBSConf() {
+ protected String validLocalCbsConf() {
return ""
+ "[{ "
+ "\"ServiceAddress\": \"localhost\","
diff --git a/src/test/java/org/onap/dcae/common/AdditionalHeaderWebTargetTest.java b/src/test/java/org/onap/dcae/common/AdditionalHeaderWebTargetTest.java
index 8f47899..3a927e1 100644
--- a/src/test/java/org/onap/dcae/common/AdditionalHeaderWebTargetTest.java
+++ b/src/test/java/org/onap/dcae/common/AdditionalHeaderWebTargetTest.java
@@ -20,31 +20,61 @@
package org.onap.dcae.common;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
-import javax.ws.rs.client.WebTarget;
-import static org.mockito.Mockito.*;
+
@RunWith(MockitoJUnitRunner.Silent.class)
public class AdditionalHeaderWebTargetTest {
-
@Test
- public void AdditionalHaderWebTargettestBase() {
+ public void additionalHaderWebTargettestBase() {
+ final Invocation.Builder mockBuilder = Mockito.mock(Invocation.Builder.class);
+
WebTarget target = mock(WebTarget.class);
- AdditionalHeaderWebTarget t = new AdditionalHeaderWebTarget(target, "aaa112", "someheader");
- t.getConfiguration();
- t.getUri();
- t.getUriBuilder();
- t.path("");
- t.register(AdditionalHeaderWebTarget.class);
- t.register(AdditionalHeaderWebTarget.class,0);
- t.register(AdditionalHeaderWebTarget.class, AdditionalHeaderWebTarget.class);
+ when(target.request()).thenReturn(mockBuilder);
+ when(target.request("application/json")).thenReturn(mockBuilder);
+ when(target.request(MediaType.APPLICATION_JSON)).thenReturn(mockBuilder);
+ JSONObject jsonObject = new JSONObject("{\"key\": 1}");
+ Map<String, Object> someMap = new HashMap<>();
+ someMap.put("id", jsonObject);
+ AdditionalHeaderWebTarget webTarget = new AdditionalHeaderWebTarget(target, "aaa112",
+ "someheader");
+ webTarget.getConfiguration();
+ webTarget.getUri();
+ webTarget.getUriBuilder();
+ webTarget.path("");
+ webTarget.register(AdditionalHeaderWebTarget.class);
+ webTarget.register(AdditionalHeaderWebTarget.class,0);
+ webTarget.register(AdditionalHeaderWebTarget.class, AdditionalHeaderWebTarget.class);
Object obj = new Object();
- t.register(obj);
- t.register(obj, 0);
- t.register(obj, AdditionalHeaderWebTarget.class);
+ webTarget.register(obj);
+ webTarget.register(obj, 0);
+ webTarget.register(obj, AdditionalHeaderWebTarget.class);
+ webTarget.request();
+ webTarget.request("application/json");
+ webTarget.request(MediaType.APPLICATION_JSON_TYPE);
+ webTarget.resolveTemplate("key", jsonObject);
+ webTarget.resolveTemplate("key", jsonObject, false);
+ webTarget.resolveTemplateFromEncoded("key", jsonObject);
+ webTarget.resolveTemplates(someMap);
+ webTarget.resolveTemplates(someMap, false);
+ webTarget.resolveTemplatesFromEncoded(someMap);
+
+ webTarget.matrixParam("key", jsonObject);
+ webTarget.queryParam("key", jsonObject);
+ webTarget.property("key", jsonObject);
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/common/AuthTypeTest.java b/src/test/java/org/onap/dcae/common/AuthTypeTest.java
index a8a8729..604730f 100644
--- a/src/test/java/org/onap/dcae/common/AuthTypeTest.java
+++ b/src/test/java/org/onap/dcae/common/AuthTypeTest.java
@@ -17,12 +17,12 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common;
-import org.junit.Test;
-import org.onap.dcae.common.AuthType;
+import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.*;
+import org.junit.Test;
public class AuthTypeTest {
diff --git a/src/test/java/org/onap/dcae/common/DataChangeEventListnerTest.java b/src/test/java/org/onap/dcae/common/DataChangeEventListnerTest.java
index 95c8012..3d48bf2 100644
--- a/src/test/java/org/onap/dcae/common/DataChangeEventListnerTest.java
+++ b/src/test/java/org/onap/dcae/common/DataChangeEventListnerTest.java
@@ -17,28 +17,21 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common;
+import static org.mockito.Mockito.when;
-import org.glassfish.jersey.media.sse.EventInput;
+import java.util.concurrent.LinkedBlockingQueue;
import org.glassfish.jersey.media.sse.InboundEvent;
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import static org.mockito.Mockito.*;
-
import org.onap.dcae.RestConfCollector;
-import org.onap.dcae.common.publishing.DMaaPConfigurationParser;
-import org.onap.dcae.common.publishing.EventPublisher;
-import org.slf4j.LoggerFactory;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.concurrent.LinkedBlockingQueue;
@RunWith(MockitoJUnitRunner.class)
public class DataChangeEventListnerTest {
@@ -59,9 +52,12 @@ public class DataChangeEventListnerTest {
DataChangeEventListener listner = new DataChangeEventListener(null);
listner.onEvent(event);
}
+
@Test
public void testDataChangeEventListenerJsonArray() {
- when(event.readData()).thenReturn("[{ \"name\":\"Ford\", \"models\":[ \"Fiesta\",\"Focus\", \"Mustang\" ] },{\"name\":\"BMW\", \"models\":[ \"320\", \"X3\",\"X5\" ] },{\"name\":\"Fiat\",\"models\":[ \"500\", \"Panda\" ]}]");
+ when(event.readData()).thenReturn("[{ \"name\":\"Ford\", \"models\":[ \"Fiesta\",\"Focus\", \"Mustang\" ] },"
+ + "{\"name\":\"BMW\", \"models\":[ \"320\", \"X3\",\"X5\" ] },{\"name\":\"Fiat\",\"models\":"
+ + "[ \"500\", \"Panda\" ]}]");
RestConfCollector.fProcessingInputQueue = new LinkedBlockingQueue<>(4);
DataChangeEventListener listner = new DataChangeEventListener(null);
listner.onEvent(event);
diff --git a/src/test/java/org/onap/dcae/common/EventConnectionStateTest.java b/src/test/java/org/onap/dcae/common/EventConnectionStateTest.java
index c6327bc..8970e73 100644
--- a/src/test/java/org/onap/dcae/common/EventConnectionStateTest.java
+++ b/src/test/java/org/onap/dcae/common/EventConnectionStateTest.java
@@ -17,11 +17,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common;
+import static org.junit.Assert.assertEquals;
+
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
+
public class EventConnectionStateTest {
@@ -30,7 +33,7 @@ public class EventConnectionStateTest {
assertEquals(EventConnectionState.INIT, EventConnectionState.fromString("init"));
assertEquals(EventConnectionState.SUBSCRIBED, EventConnectionState.fromString("subscribed"));
assertEquals(EventConnectionState.UNSUBSCRIBED, EventConnectionState.fromString("unsubscribed"));
- assertEquals(EventConnectionState.Unspecified, EventConnectionState.fromString("unspecified"));
+ assertEquals(EventConnectionState.UNSPECIFIED, EventConnectionState.fromString("unspecified"));
}
@Test(expected = IllegalArgumentException.class)
diff --git a/src/test/java/org/onap/dcae/common/EventProcessorTest.java b/src/test/java/org/onap/dcae/common/EventProcessorTest.java
index 04a2952..e86af85 100644
--- a/src/test/java/org/onap/dcae/common/EventProcessorTest.java
+++ b/src/test/java/org/onap/dcae/common/EventProcessorTest.java
@@ -17,14 +17,18 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.LinkedBlockingQueue;
import org.json.JSONObject;
import org.junit.Before;
-
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -38,25 +42,9 @@ import org.onap.dcae.controller.AccessController;
import org.onap.dcae.controller.PersistentEventConnection;
import org.slf4j.LoggerFactory;
-
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.concurrent.LinkedBlockingQueue;
-
-
-
-import static io.vavr.API.Map;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.when;
-import static org.onap.dcae.common.publishing.DMaaPConfigurationParser.parseToDomainMapping;
-
@RunWith(MockitoJUnitRunner.Silent.class)
public class EventProcessorTest {
-
-
@Mock
private ApplicationSettings properties;
@@ -72,10 +60,13 @@ public class EventProcessorTest {
protected static final Path RCC_KEYSTORE_PASSWORD_FILE = Paths.get(RESOURCES.toString(), "rcc_passwordfile");
protected static final Path RCC_KEYSTORE = Paths.get(RESOURCES.toString(), "sdnc.p12");
+ /**
+ * set up before testcase.
+ */
@Before
public void setUp() {
- eventPublisher = EventPublisher.createPublisher(LoggerFactory.getLogger("some_log"), DMaaPConfigurationParser.
- parseToDomainMapping(path).get());
+ eventPublisher = EventPublisher.createPublisher(LoggerFactory.getLogger("some_log"),
+ DMaaPConfigurationParser.parseToDomainMapping(path).get());
streamMap = RestConfCollector.parseStreamIdToStreamHashMapping("notification=device-registration");
}
@@ -83,59 +74,77 @@ public class EventProcessorTest {
@Test
public void testEventProcessorRunException() {
try {
- when(properties.truststoreFileLocation()).thenReturn(TRUSTSTORE.toString());
-
- when(properties.truststorePasswordFileLocation()).thenReturn(TRUSTSTORE_PASSWORD_FILE.toString());
- when(properties.keystoreFileLocation()).thenReturn(KEYSTORE.toString());
- when(properties.keystorePasswordFileLocation()).thenReturn(KEYSTORE_PASSWORD_FILE.toString());
- when(properties.rccKeystoreFileLocation()).thenReturn(RCC_KEYSTORE.toString());
- when(properties.rccKeystorePasswordFileLocation()).thenReturn(RCC_KEYSTORE_PASSWORD_FILE.toString());
- when(properties.controllerConfigFileLocation()).thenReturn(Paths.get("etc/ont_config.json").toAbsolutePath().toString());
-
- RestapiCallNode restApiCallNode = Mockito.mock(RestapiCallNode.class);
- Mockito.doNothing().when(restApiCallNode).sendRequest(any(), any(), any());
-
-
- JSONObject controller = new JSONObject(
- "{\"controller_name\":\"AccessM&C\",\"controller_restapiUrl\":\"10.118.191.43:26335\",\"controller_restapiUser\":\"access\",\"controller_restapiPassword\":\"Huawei@123\",\"controller_accessTokenUrl\":\"/rest/plat/smapp/v1/oauth/token\",\"controller_accessTokenFile\":\"./etc/access-token.json\",\"controller_accessTokenMethod\":\"put\",\"controller_subsMethod\":\"post\",\"controller_subscriptionUrl\":\"/restconf/v1/operations/huawei-nce-notification-action:establish-subscription\",\"controller_disableSsl\":\"true\",\"event_details\":[{\"event_name\":\"ONT_registration\",\"event_description\":\"ONTregistartionevent\",\"event_sseventUrlEmbed\":\"true\",\"event_sseventsField\":\"output.url\",\"event_sseventsUrl\":\"null\",\"event_subscriptionTemplate\":\"./etc/ont_registartion_subscription_template.json\",\"event_unSubscriptionTemplate\":\"./etc/ont_registartion_unsubscription_template.json\",\"event_ruleId\":\"777777777\"}]}");
- AccessController acClr = new AccessController(controller, properties);
-
- PersistentEventConnection p = new PersistentEventConnection.PersistentEventConnectionBuilder().setEventName("")
- .setEventDescription("").setEventSseventUrlEmbed(true).setEventSseventsField("").setEventSseventsUrl("")
- .setEventSubscriptionTemplate("").setEventUnSubscriptionTemplate("").setEventRuleId("1234646346")
- .setParentCtrllr(acClr).setModifyEvent(true).setModifyMethod("modifyOntEvent")
- .setUserData("remote_id=AC9.0234.0337;svlan=1001;macAddress=00:11:22:33:44:55;")
- .createPersistentEventConnection();
- p.getEventParamMapValue("restapiUrl");
- p.modifyEventParamMap("restapiUrl", "10.118.191.43:26335");
- RestConfCollector.fProcessingInputQueue = new LinkedBlockingQueue<>(4);
- p.getParentCtrllr().setRestApiCallNode(restApiCallNode);
- RestConfCollector.fProcessingInputQueue.offer(new EventData(p, new JSONObject("{\n" +
- " \"notification\" : {\n" +
- " \"notification-id\" : \"01010101011\",\n" +
- " \"event-time\" : \"2019-3-9T3:30:30.547z\",\n" +
- " \"message\" : {\n" +
- " \"object-type\" : \"onu\",\n" +
- " \"topic\" : \"resources\",\n" +
- " \"version\" : \"v1\",\n" +
- " \"operation\" : \"create\",\n" +
- " \"content\" : {\n" +
- " \"onu\" : {\n" +
- " \"alias\" : \"\",\n" +
- " \"refParentLTP\" : \"gpon.0.5.1\",\n" +
- " \"sn\" : \"HWTCC01B7503\",\n" +
- " \"refParentLTPNativeId\" : \"NE=167772165,FR=0,S=5,CP=-1,PP=||1|\",\n" +
- " \"onuId\": \"\",\n" +
- " \"refParentNE\" : \"aaaaaaaaa-aaaaa-aaaa-aaaa-aaa167772165\",\n" +
- " \"refParentNeNativeId\": \"NE=167772165\"\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- "}")));
- RestConfCollector.fProcessingInputQueue.offer(new EventData(null, null));
- EventProcessor ev = new EventProcessor(eventPublisher, streamMap);
- ev.run();
- } catch (Exception e){}
+ when(properties.truststoreFileLocation()).thenReturn(TRUSTSTORE.toString());
+ when(properties.truststorePasswordFileLocation()).thenReturn(TRUSTSTORE_PASSWORD_FILE.toString());
+ when(properties.keystoreFileLocation()).thenReturn(KEYSTORE.toString());
+ when(properties.keystorePasswordFileLocation()).thenReturn(KEYSTORE_PASSWORD_FILE.toString());
+ when(properties.rccKeystoreFileLocation()).thenReturn(RCC_KEYSTORE.toString());
+ when(properties.rccKeystorePasswordFileLocation()).thenReturn(RCC_KEYSTORE_PASSWORD_FILE.toString());
+ when(properties.controllerConfigFileLocation())
+ .thenReturn(Paths.get("etc/ont_config.json").toAbsolutePath().toString());
+
+ RestapiCallNode restApiCallNode = Mockito.mock(RestapiCallNode.class);
+ Mockito.doNothing().when(restApiCallNode).sendRequest(any(), any(), any());
+
+
+ JSONObject controller = new JSONObject(
+ "{\"controller_name\":\"AccessM&C\",\"controller_restapiUrl\":\"10.118.191.43:26335\","
+ + "\"controller_restapiUser\":\"access\",\"controller_restapiPassword\":\"Huawei@123\","
+ + "\"controller_accessTokenUrl\":\"/rest/plat/smapp/v1/oauth/token\","
+ + "\"controller_accessTokenFile\":\"./etc/access-token.json\","
+ + "\"controller_accessTokenMethod\":\"put\",\"controller_subsMethod\":\"post\","
+ + "\"controller_subscriptionUrl\":"
+ + "\"/restconf/v1/operations/huawei-nce-notification-action:establish-subscription\","
+ + "\"controller_disableSsl\":\"true\",\"event_details\":[{\"event_name\":"
+ + "\"ONT_registration\",\"event_description\":\"ONTregistartionevent\","
+ + "\"event_sseventUrlEmbed\":\"true\",\"event_sseventsField\":\"output.url\","
+ + "\"event_sseventsUrl\":\"null\","
+ + "\"event_subscriptionTemplate\":\"./etc/ont_registartion_subscription_template.json\","
+ + "\"event_unSubscriptionTemplate\":"
+ + "\"./etc/ont_registartion_unsubscription_template.json\","
+ + "\"event_ruleId\":\"777777777\"}]}");
+ AccessController acClr = new AccessController(controller, properties);
+
+ PersistentEventConnection eventConnection = new PersistentEventConnection.PersistentEventConnectionBuilder()
+ .setEventName("")
+ .setEventDescription("").setEventSseventUrlEmbed(true).setEventSseventsField("")
+ .setEventSseventsUrl("")
+ .setEventSubscriptionTemplate("").setEventUnSubscriptionTemplate("").setEventRuleId("1234646346")
+ .setParentCtrllr(acClr).setModifyEvent(true).setModifyMethod("modifyOntEvent")
+ .setUserData("remote_id=AC9.0234.0337;svlan=1001;macAddress=00:11:22:33:44:55;")
+ .createPersistentEventConnection();
+ eventConnection.getEventParamMapValue("restapiUrl");
+ eventConnection.modifyEventParamMap("restapiUrl", "10.118.191.43:26335");
+ RestConfCollector.fProcessingInputQueue = new LinkedBlockingQueue<>(4);
+ eventConnection.getParentCtrllr().setRestApiCallNode(restApiCallNode);
+ RestConfCollector.fProcessingInputQueue.offer(new EventData(eventConnection, new JSONObject("{\n"
+ + " \"notification\" : {\n"
+ + " \"notification-id\" : \"01010101011\",\n"
+ + " \"event-time\" : \"2019-3-9T3:30:30.547z\",\n"
+ + " \"message\" : {\n"
+ + " \"object-type\" : \"onu\",\n"
+ + " \"topic\" : \"resources\",\n"
+ + " \"version\" : \"v1\",\n"
+ + " \"operation\" : \"create\",\n"
+ + " \"content\" : {\n"
+ + " \"onu\" : {\n"
+ + " \"alias\" : \"\",\n"
+ + " \"refParentLTP\" : \"gpon.0.5.1\",\n"
+ + " \"sn\" : \"HWTCC01B7503\",\n"
+ + " \"refParentLTPNativeId\" : \"NE=167772165,FR=0,S=5,CP=-1,PP=||1|\",\n"
+ + " \"onuId\": \"\",\n"
+ + " \"refParentNE\" : \"aaaaaaaaa-aaaaa-aaaa-aaaa-aaa167772165\",\n"
+ + " \"refParentNeNativeId\": \"NE=167772165\"\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + "}")));
+ RestConfCollector.fProcessingInputQueue.offer(new EventData(null, null));
+ EventProcessor ev = new EventProcessor(eventPublisher, streamMap);
+ ev.run();
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/common/FormatTest.java b/src/test/java/org/onap/dcae/common/FormatTest.java
index e54dd9b..61e9e85 100644
--- a/src/test/java/org/onap/dcae/common/FormatTest.java
+++ b/src/test/java/org/onap/dcae/common/FormatTest.java
@@ -17,13 +17,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common;
-import org.junit.Test;
-import org.onap.dcae.common.Format;
import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
public class FormatTest {
@Test
diff --git a/src/test/java/org/onap/dcae/common/RestApiCallNodeTest.java b/src/test/java/org/onap/dcae/common/RestApiCallNodeTest.java
index 3534a6c..3b533e9 100644
--- a/src/test/java/org/onap/dcae/common/RestApiCallNodeTest.java
+++ b/src/test/java/org/onap/dcae/common/RestApiCallNodeTest.java
@@ -20,20 +20,26 @@
package org.onap.dcae.common;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
import com.sun.jersey.api.client.WebResource;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+import javax.ws.rs.core.MultivaluedHashMap;
import org.glassfish.jersey.client.ClientResponse;
import org.junit.Test;
import org.mockito.Mockito;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.*;
public class RestApiCallNodeTest {
@Test
- public void RestApiCallNodeTestSendEmptyMessageNoTemplate() {
+ public void restApiCallNodeTestSendEmptyMessageNoTemplate() {
RestapiCallNode rest = new RestapiCallNode();
RestConfContext ctx = new RestConfContext();
Map<String, String> paraMap = new HashMap<>();
@@ -65,8 +71,8 @@ public class RestApiCallNodeTest {
String trustPassword = "admin";
paraMap.put(Constants.KSETTING_TRUST_STORE_PASSWORD, trustPassword);
paraMap.put(Constants.KSETTING_KEY_STORE_FILENAME, null);
- String KeyPassword = "admin";
- paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, KeyPassword);
+ String keyPassword = "admin";
+ paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, keyPassword);
WebResource webResource = mock(WebResource.class);
@@ -77,11 +83,13 @@ public class RestApiCallNodeTest {
when(webResource.accept(anyString())).thenReturn(webResourceBuilder);
rest.sendRequest(paraMap, ctx, 1);
- }catch (Exception e){}
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
@Test
- public void RestApiCallNodeTestSendEmptyMessageWithTemplate() {
+ public void restApiCallNodeTestSendEmptyMessageWithTemplate() {
RestapiCallNode rest = new RestapiCallNode();
RestConfContext ctx = new RestConfContext();
Map<String, String> paraMap = new HashMap<>();
@@ -97,7 +105,7 @@ public class RestApiCallNodeTest {
paraMap.put(Constants.KSETTING_REST_PASSWD, null);
paraMap.put(Constants.KDEFAULT_REQUESTBODY, null);
- paraMap.put(Constants.KSETTING_AUTH_TYPE, "unspecified");
+ paraMap.put(Constants.KSETTING_AUTH_TYPE, "digest");
paraMap.put(Constants.KSETTING_CONTENT_TYPE, "application/json");
paraMap.put(Constants.KSETTING_OAUTH_CONSUMER_KEY, null);
paraMap.put(Constants.KSETTING_OAUTH_CONSUMER_SECRET, null);
@@ -113,9 +121,60 @@ public class RestApiCallNodeTest {
String trustPassword = "admin";
paraMap.put(Constants.KSETTING_TRUST_STORE_PASSWORD, trustPassword);
paraMap.put(Constants.KSETTING_KEY_STORE_FILENAME, null);
- String KeyPassword = "admin";
- paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, KeyPassword);
+ String keyPassword = "admin";
+ paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, keyPassword);
+
+
+ WebResource webResource = mock(WebResource.class);
+ WebResource.Builder webResourceBuilder = mock(WebResource.Builder.class);
+ ClientResponse clientResponse = mock(ClientResponse.class);
+ try {
+ Mockito.doNothing().when(webResourceBuilder).method("post");
+ when(webResource.accept(anyString())).thenReturn(webResourceBuilder);
+
+ rest.sendRequest(paraMap, ctx, 1);
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
+ }
+
+ @Test
+ public void restApiCallNodeTestSkipSending() {
+ RestapiCallNode rest = new RestapiCallNode();
+ RestConfContext ctx = new RestConfContext();
+ Map<String, String> paraMap = new HashMap<>();
+ paraMap.put(Constants.KDEFAULT_TEMP_FILENAME, null);
+ paraMap.put(Constants.KSETTING_REST_API_URL, "https://127.0.0.1:8080/rest/sample");
+ paraMap.put(Constants.KSETTING_HTTP_METHOD, "post");
+ paraMap.put(Constants.KSETTING_RESP_PREFIX, "responsePrefix");
+ paraMap.put(Constants.KSETTING_SKIP_SENDING, "false");
+ paraMap.put(Constants.KSETTING_SSE_CONNECT_URL, null);
+ paraMap.put(Constants.KSETTING_FORMAT, "json");
+
+ paraMap.put(Constants.KSETTING_REST_UNAME, null);
+ paraMap.put(Constants.KSETTING_REST_PASSWD, null);
+ paraMap.put(Constants.KDEFAULT_REQUESTBODY, null);
+ paraMap.put(Constants.KSETTING_AUTH_TYPE, "unspecified");
+ paraMap.put(Constants.KSETTING_CONTENT_TYPE, "application/json");
+ paraMap.put(Constants.KSETTING_OAUTH_CONSUMER_KEY, null);
+ paraMap.put(Constants.KSETTING_OAUTH_CONSUMER_SECRET, null);
+ paraMap.put(Constants.KSETTING_OAUTH_SIGNATURE_METHOD, null);
+ paraMap.put(Constants.KSETTING_OAUTH_VERSION, null);
+
+ paraMap.put(Constants.KSETTING_CUSTOMHTTP_HEADER, null);
+ paraMap.put(Constants.KSETTING_TOKENID, null);
+ paraMap.put(Constants.KSETTING_DUMP_HEADER, "false");
+ paraMap.put(Constants.KSETTING_RETURN_REQUEST_PAYLOAD, "false");
+
+ paraMap.put(Constants.KSETTING_TRUST_STORE_FILENAME, null);
+ String trustPassword = "admin";
+ paraMap.put(Constants.KSETTING_TRUST_STORE_PASSWORD, trustPassword);
+ paraMap.put(Constants.KSETTING_KEY_STORE_FILENAME, null);
+ String keyPassword = "admin";
+ paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, keyPassword);
+ paraMap.put(Constants.KDEFAULT_DISABLE_SSL, "false");
+ paraMap.put(Constants.KSETTING_SKIP_SENDING, "true");
WebResource webResource = mock(WebResource.class);
WebResource.Builder webResourceBuilder = mock(WebResource.Builder.class);
@@ -123,9 +182,119 @@ public class RestApiCallNodeTest {
try {
Mockito.doNothing().when(webResourceBuilder).method("post");
when(webResource.accept(anyString())).thenReturn(webResourceBuilder);
+ rest.sendRequest(paraMap, ctx, 1);
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
+ }
+
+ @Test
+ public void restApiCallNodeTestHttpResponse() {
+ RestapiCallNode rest = spy(RestapiCallNode.class);
+ RestConfContext ctx = new RestConfContext();
+ Map<String, String> paraMap = new HashMap<>();
+ paraMap.put(Constants.KDEFAULT_TEMP_FILENAME, null);
+ paraMap.put(Constants.KSETTING_REST_API_URL, "https://127.0.0.1:8080/rest/sample");
+ paraMap.put(Constants.KSETTING_HTTP_METHOD, "post");
+ paraMap.put(Constants.KSETTING_RESP_PREFIX, "responsePrefix");
+ paraMap.put(Constants.KSETTING_SKIP_SENDING, "false");
+ paraMap.put(Constants.KSETTING_SSE_CONNECT_URL, null);
+ paraMap.put(Constants.KSETTING_FORMAT, "json");
+
+ paraMap.put(Constants.KSETTING_REST_UNAME, null);
+ paraMap.put(Constants.KSETTING_REST_PASSWD, null);
+ paraMap.put(Constants.KDEFAULT_REQUESTBODY, null);
+ paraMap.put(Constants.KSETTING_AUTH_TYPE, "unspecified");
+ paraMap.put(Constants.KSETTING_CONTENT_TYPE, "application/json");
+ paraMap.put(Constants.KSETTING_OAUTH_CONSUMER_KEY, null);
+ paraMap.put(Constants.KSETTING_OAUTH_CONSUMER_SECRET, null);
+ paraMap.put(Constants.KSETTING_OAUTH_SIGNATURE_METHOD, null);
+ paraMap.put(Constants.KSETTING_OAUTH_VERSION, null);
+
+ paraMap.put(Constants.KSETTING_CUSTOMHTTP_HEADER, null);
+ paraMap.put(Constants.KSETTING_TOKENID, null);
+ paraMap.put(Constants.KSETTING_DUMP_HEADER, "false");
+ paraMap.put(Constants.KSETTING_RETURN_REQUEST_PAYLOAD, "false");
+
+ paraMap.put(Constants.KSETTING_TRUST_STORE_FILENAME, null);
+ String trustPassword = "admin";
+ paraMap.put(Constants.KSETTING_TRUST_STORE_PASSWORD, trustPassword);
+ paraMap.put(Constants.KSETTING_KEY_STORE_FILENAME, null);
+ String keyPassword = "admin";
+ paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, keyPassword);
+ paraMap.put(Constants.KDEFAULT_DISABLE_SSL, "false");
+ paraMap.put(Constants.KSETTING_SKIP_SENDING, "true");
+
+ WebResource webResource = mock(WebResource.class);
+ WebResource.Builder webResourceBuilder = mock(WebResource.Builder.class);
+ ClientResponse clientResponse = mock(ClientResponse.class);
+ HttpResponse response = new HttpResponse();
+ response.code = 200;
+ response.body = "{\"prop2\"=\"value\", \"prop1\"=\"value\"}";;
+ response.message = "Some message";
+ response.headers = new MultivaluedHashMap<>();
+ response.headers.add("connection", "close");
+ response.headers.add("content-encoding", "gzip");
+ try {
+ Mockito.doNothing().when(webResourceBuilder).method("post");
+ when(webResource.accept(anyString())).thenReturn(webResourceBuilder);
+ doReturn(response).when(rest).sendHttpRequest(any(), any());
rest.sendRequest(paraMap, ctx, 1);
- }catch (Exception e){}
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
+ @Test
+ public void restApiCallNodeTestWithSsl() {
+ RestapiCallNode rest = new RestapiCallNode();
+ RestConfContext ctx = new RestConfContext();
+ Map<String, String> paraMap = new HashMap<>();
+ paraMap.put(Constants.KDEFAULT_TEMP_FILENAME, null);
+ paraMap.put(Constants.KSETTING_REST_API_URL, "https://127.0.0.1:8080/rest/sample");
+ paraMap.put(Constants.KSETTING_HTTP_METHOD, "post");
+ paraMap.put(Constants.KSETTING_RESP_PREFIX, "responsePrefix");
+ paraMap.put(Constants.KSETTING_SKIP_SENDING, "false");
+ paraMap.put(Constants.KSETTING_SSE_CONNECT_URL, null);
+ paraMap.put(Constants.KSETTING_FORMAT, "json");
+
+ paraMap.put(Constants.KSETTING_REST_UNAME, null);
+ paraMap.put(Constants.KSETTING_REST_PASSWD, null);
+ paraMap.put(Constants.KDEFAULT_REQUESTBODY, null);
+
+ paraMap.put(Constants.KSETTING_AUTH_TYPE, "unspecified");
+ paraMap.put(Constants.KSETTING_CONTENT_TYPE, "application/json");
+ paraMap.put(Constants.KSETTING_OAUTH_CONSUMER_KEY, null);
+ paraMap.put(Constants.KSETTING_OAUTH_CONSUMER_SECRET, null);
+ paraMap.put(Constants.KSETTING_OAUTH_SIGNATURE_METHOD, null);
+ paraMap.put(Constants.KSETTING_OAUTH_VERSION, null);
+
+ paraMap.put(Constants.KSETTING_CUSTOMHTTP_HEADER, null);
+ paraMap.put(Constants.KSETTING_TOKENID, null);
+ paraMap.put(Constants.KSETTING_DUMP_HEADER, "false");
+ paraMap.put(Constants.KSETTING_RETURN_REQUEST_PAYLOAD, "false");
+ paraMap.put(Constants.KSETTING_SKIP_SENDING, "true");
+
+ paraMap.put(Constants.KSETTING_TRUST_STORE_FILENAME, "src/test/resources/truststore");
+ String trustPassword = "vestest";
+ paraMap.put(Constants.KSETTING_TRUST_STORE_PASSWORD, trustPassword);
+ paraMap.put(Constants.KSETTING_KEY_STORE_FILENAME, "src/test/resources/keystore");
+ String keyPassword = "vestest";
+ paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, keyPassword);
+ paraMap.put(Constants.KDEFAULT_DISABLE_SSL, "false");
+
+ WebResource webResource = mock(WebResource.class);
+ WebResource.Builder webResourceBuilder = mock(WebResource.Builder.class);
+ ClientResponse clientResponse = mock(ClientResponse.class);
+
+ try {
+ Mockito.doNothing().when(webResourceBuilder).method("post");
+ when(webResource.accept(anyString())).thenReturn(webResourceBuilder);
+
+ rest.sendRequest(paraMap, ctx, 1);
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
+ }
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/common/RestConfContextTest.java b/src/test/java/org/onap/dcae/common/RestConfContextTest.java
index 00b07f8..c8bfe48 100644
--- a/src/test/java/org/onap/dcae/common/RestConfContextTest.java
+++ b/src/test/java/org/onap/dcae/common/RestConfContextTest.java
@@ -20,10 +20,13 @@
package org.onap.dcae.common;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import org.junit.Test;
-import org.onap.dcae.common.RestConfContext;
-import static org.junit.Assert.*;
+
public class RestConfContextTest {
@@ -47,6 +50,7 @@ public class RestConfContextTest {
RestConfContext restConfContext = new RestConfContext();
restConfContext.setAttribute(key,value);
restConfContext.setAttribute(key1,value1);
- assertTrue(restConfContext.getAttributeKeySet().contains(key) && restConfContext.getAttributeKeySet().contains(key1));
+ assertTrue(restConfContext.getAttributeKeySet().contains(key)
+ && restConfContext.getAttributeKeySet().contains(key1));
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/common/XmlJsonUtilTest.java b/src/test/java/org/onap/dcae/common/XmlJsonUtilTest.java
index f05541f..d34e508 100644
--- a/src/test/java/org/onap/dcae/common/XmlJsonUtilTest.java
+++ b/src/test/java/org/onap/dcae/common/XmlJsonUtilTest.java
@@ -20,15 +20,13 @@
package org.onap.dcae.common;
-import org.json.XML;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
+import org.junit.Test;
+
-import static org.junit.Assert.assertEquals;
public class XmlJsonUtilTest {
@@ -43,29 +41,33 @@ public class XmlJsonUtilTest {
mm.put("result.output", "xml2json");
mm.put("result.[", "start");
mm.put("result.]", "end");
- mm.put("result.list", "<LIST>\n" +
- " <LITERAL VALUE=\"\"/>\n" +
- " </LIST>");
+ mm.put("result.list", "<LIST>\n"
+ + " <LITERAL VALUE=\"\"/>\n"
+ + " </LIST>");
try {
String str = XmlJsonUtil.getXml(mm, var);
assertEquals(str.startsWith("<"), true);
String str2 = XmlJsonUtil.getJson(mm, var);
assertEquals(str2.startsWith("{"), true);
- }catch (Exception e) {}
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
@Test
public void removeEmptystructFromXml() {
- String var = "<time>2018 12:04</time>\n" +
- "<output>t2</output>\n" +
- "<start>bad\n" +
- "<status>200</status>";
+ String var = "<time>2018 12:04</time>\n"
+ + "<output>t2</output>\n"
+ + "<start>bad\n"
+ + "<status>200</status>";
Map<String, String> mm = new HashMap<>();
try {
String str = XmlJsonUtil.removeEmptyStructXml(var);
- }catch (Exception e) {}
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
@Test
@@ -75,14 +77,37 @@ public class XmlJsonUtilTest {
try {
String str = XmlJsonUtil.removeEmptyStructJson(var);
- }catch (Exception e) {}
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
@Test
public void removeLastCommaJson() {
- String var2 ="{\"name\":\"john\",\"age\":22,\"class\":\"mca\", \"data\":{}, \"arr\" : [\"some\" : {},],}";
+ String var2 = "{\"name\":\"john\",\"age\":22,\"class\":\"mca\", \"data\":{}, \"arr\" : [\"some\" : {},],}";
try {
String str = XmlJsonUtil.removeLastCommaJson(var2);
- }catch (Exception e) {}
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
+
+ @Test
+ public void getJsonOrXmlTest2() {
+ String var = "result";
+ Map<String, String> mm = new HashMap<>();
+
+ mm.put("result[0]", "{\"metaname\": \"remote-id\",\"metaval\": "
+ + "\"AC9.0234.0337\",\"resource-version\": \"1553802421110\"}");
+ mm.put("result[1]", "{\"metaname\": \"remote-id\",\"metaval\": "
+ + "\"AC9.0234.0337\",\"resource-version\": \"1553802421110\"}");
+
+ try {
+ String str2 = XmlJsonUtil.getJson(mm, var);
+ assertEquals(str2.startsWith("["), true);
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
+ }
+
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/common/XmlParserTest.java b/src/test/java/org/onap/dcae/common/XmlParserTest.java
index b005c89..5ca80c0 100644
--- a/src/test/java/org/onap/dcae/common/XmlParserTest.java
+++ b/src/test/java/org/onap/dcae/common/XmlParserTest.java
@@ -20,27 +20,26 @@
package org.onap.dcae.common;
-import org.junit.Test;
-
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-
-import static org.junit.Assert.*;
+import org.junit.Test;
public class XmlParserTest {
@Test
public void setAttribute() {
- String convert = "<time>2018 12:04</time>\n" +
- "<output>t2</output>\n" +
- "<status>200</status>";
+ String convert = "<time>2018 12:04</time>\n"
+ + "<output>t2</output>\n"
+ + "<status>200</status>";
Set<String> listNameList = new HashSet<>();
listNameList.add("result");
Map<String, String> propMap;
try {
propMap = XmlParser.convertToProperties(convert, listNameList);
System.out.println(propMap);
- }catch (Exception e) {}
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/common/publishing/DMaaPEventPublisherTest.java b/src/test/java/org/onap/dcae/common/publishing/DMaaPEventPublisherTest.java
index 2865b75..79ac03b 100644
--- a/src/test/java/org/onap/dcae/common/publishing/DMaaPEventPublisherTest.java
+++ b/src/test/java/org/onap/dcae/common/publishing/DMaaPEventPublisherTest.java
@@ -18,6 +18,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common.publishing;
import static io.vavr.API.Option;
@@ -40,14 +41,17 @@ public class DMaaPEventPublisherTest {
private DMaaPEventPublisher eventPublisher;
private CambriaBatchingPublisher cambriaPublisher;
- private DMaaPPublishersCache DMaaPPublishersCache;
+ private DMaaPPublishersCache dmaapPublishersCache;
+ /**
+ * Setup before test.
+ */
@Before
public void setUp() {
cambriaPublisher = mock(CambriaBatchingPublisher.class);
- DMaaPPublishersCache = mock(DMaaPPublishersCache.class);
- when(DMaaPPublishersCache.getPublisher(anyString())).thenReturn(Option(cambriaPublisher));
- eventPublisher = new DMaaPEventPublisher(DMaaPPublishersCache, mock(Logger.class));
+ dmaapPublishersCache = mock(DMaaPPublishersCache.class);
+ when(dmaapPublishersCache.getPublisher(anyString())).thenReturn(Option(cambriaPublisher));
+ eventPublisher = new DMaaPEventPublisher(dmaapPublishersCache, mock(Logger.class));
}
@Test
@@ -74,6 +78,6 @@ public class DMaaPEventPublisherTest {
eventPublisher.sendEvent(event, STREAM_ID);
// then
- verify(DMaaPPublishersCache).closePublisherFor(STREAM_ID);
+ verify(dmaapPublishersCache).closePublisherFor(STREAM_ID);
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/common/publishing/DMaaPPublishersCacheTest.java b/src/test/java/org/onap/dcae/common/publishing/DMaaPPublishersCacheTest.java
index 2884e44..6f3696d 100644
--- a/src/test/java/org/onap/dcae/common/publishing/DMaaPPublishersCacheTest.java
+++ b/src/test/java/org/onap/dcae/common/publishing/DMaaPPublishersCacheTest.java
@@ -18,6 +18,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common.publishing;
import static io.vavr.API.List;
@@ -43,22 +44,41 @@ import org.onap.dcae.common.publishing.DMaaPPublishersCache.OnPublisherRemovalLi
public class DMaaPPublishersCacheTest {
private String streamId1;
- private Map<String, PublisherConfig> dMaaPConfigs;
-
+ private Map<String, PublisherConfig> dmaapconfigs;
+ private Map<String, PublisherConfig> dmaapconfigs2;
+ /**
+ * Setup before test.
+ */
@Before
public void setUp() {
streamId1 = "sampleStream1";
- dMaaPConfigs = Map("sampleStream1", new PublisherConfig(List("destination1"), "topic1"));
+ dmaapconfigs = Map("sampleStream1", new PublisherConfig(List("destination1"), "topic1"));
+ dmaapconfigs2 = Map("sampleStream1", new PublisherConfig(List("destination1"),
+ "topic1", "user", "pass"));
+
}
@Test
public void shouldReturnTheSameCachedInstanceOnConsecutiveRetrievals() {
// given
- DMaaPPublishersCache dMaaPPublishersCache = new DMaaPPublishersCache(dMaaPConfigs);
+ DMaaPPublishersCache dmaapPublishersCache = new DMaaPPublishersCache(dmaapconfigs);
+
+ // when
+ Option<CambriaBatchingPublisher> firstPublisher = dmaapPublishersCache.getPublisher(streamId1);
+ Option<CambriaBatchingPublisher> secondPublisher = dmaapPublishersCache.getPublisher(streamId1);
+
+ // then
+ assertSame("should return same instance", firstPublisher.get(), secondPublisher.get());
+ }
+
+ @Test
+ public void shouldReturnTheSameCachedInstanceOnConsecutiveRetrievals2() {
+ // given
+ DMaaPPublishersCache dmaapPublishersCache = new DMaaPPublishersCache(dmaapconfigs2);
// when
- Option<CambriaBatchingPublisher> firstPublisher = dMaaPPublishersCache.getPublisher(streamId1);
- Option<CambriaBatchingPublisher> secondPublisher = dMaaPPublishersCache.getPublisher(streamId1);
+ Option<CambriaBatchingPublisher> firstPublisher = dmaapPublishersCache.getPublisher(streamId1);
+ Option<CambriaBatchingPublisher> secondPublisher = dmaapPublishersCache.getPublisher(streamId1);
// then
assertSame("should return same instance", firstPublisher.get(), secondPublisher.get());
@@ -69,14 +89,14 @@ public class DMaaPPublishersCacheTest {
// given
CambriaBatchingPublisher cambriaPublisherMock1 = mock(CambriaBatchingPublisher.class);
CambriaPublishersCacheLoader cacheLoaderMock = mock(CambriaPublishersCacheLoader.class);
- DMaaPPublishersCache dMaaPPublishersCache = new DMaaPPublishersCache(cacheLoaderMock,
+ DMaaPPublishersCache dmaapPublishersCache = new DMaaPPublishersCache(cacheLoaderMock,
new OnPublisherRemovalListener(),
- dMaaPConfigs);
+ dmaapconfigs);
when(cacheLoaderMock.load(streamId1)).thenReturn(cambriaPublisherMock1);
// when
- dMaaPPublishersCache.getPublisher(streamId1);
- dMaaPPublishersCache.closePublisherFor(streamId1);
+ dmaapPublishersCache.getPublisher(streamId1);
+ dmaapPublishersCache.closePublisherFor(streamId1);
// then
verify(cambriaPublisherMock1).close(20, TimeUnit.SECONDS);
@@ -84,12 +104,12 @@ public class DMaaPPublishersCacheTest {
}
@Test
- public void shouldReturnNoneIfThereIsNoDMaaPConfigurationForGivenStreamID() {
+ public void shouldReturnNoneIfThereIsNoDmaaPConfigurationForGivenStreamId() {
// given
- DMaaPPublishersCache dMaaPPublishersCache = new DMaaPPublishersCache(dMaaPConfigs);
+ DMaaPPublishersCache dmaapPublishersCache = new DMaaPPublishersCache(dmaapconfigs);
// then
- assertTrue("should not exist", dMaaPPublishersCache.getPublisher("non-existing").isEmpty());
+ assertTrue("should not exist", dmaapPublishersCache.getPublisher("non-existing").isEmpty());
}
@@ -106,19 +126,22 @@ public class DMaaPPublishersCacheTest {
secondDomain,
new PublisherConfig(List("destination2"), "topic2",
"user", "pass"));
- Map<String, PublisherConfig> newConfig = Map(firstDomain, new PublisherConfig(List("destination1"), "topic1"),
- secondDomain, new PublisherConfig(List("destination2"), "topic2"));
- DMaaPPublishersCache dMaaPPublishersCache = new DMaaPPublishersCache(cacheLoaderMock,
+
+ DMaaPPublishersCache dmaapPublishersCache = new DMaaPPublishersCache(cacheLoaderMock,
new OnPublisherRemovalListener(),
oldConfig);
+ final Map<String, PublisherConfig> newConfig = Map(firstDomain,
+ new PublisherConfig(List("destination1"), "topic1"),
+ secondDomain, new PublisherConfig(List("destination2"), "topic2"));
+
when(cacheLoaderMock.load(firstDomain)).thenReturn(cambriaPublisherMock1);
when(cacheLoaderMock.load(secondDomain)).thenReturn(cambriaPublisherMock2);
- dMaaPPublishersCache.getPublisher(firstDomain);
- dMaaPPublishersCache.getPublisher(secondDomain);
+ dmaapPublishersCache.getPublisher(firstDomain);
+ dmaapPublishersCache.getPublisher(secondDomain);
// when
- dMaaPPublishersCache.reconfigure(newConfig);
+ dmaapPublishersCache.reconfigure(newConfig);
// then
verify(cambriaPublisherMock2).close(20, TimeUnit.SECONDS);
diff --git a/src/test/java/org/onap/dcae/common/publishing/JsonParserTest.java b/src/test/java/org/onap/dcae/common/publishing/JsonParserTest.java
index f00df2c..54d0cfc 100644
--- a/src/test/java/org/onap/dcae/common/publishing/JsonParserTest.java
+++ b/src/test/java/org/onap/dcae/common/publishing/JsonParserTest.java
@@ -17,22 +17,30 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common.publishing;
-import java.util.Map;
+import static org.junit.Assert.assertEquals;
+import java.util.Map;
import org.junit.Test;
import org.onap.dcae.common.JsonParser;
-import junit.framework.Assert;
-
-
public class JsonParserTest {
- @Test
- public void convertToPropertiesTest() throws Exception {
- String testJson="{\"prop2\"=\"value\", \"prop1\"=\"value\"}";
- Map<String, String> response= JsonParser.convertToProperties(testJson);
- Assert.assertEquals("value", response.get("prop2"));
- }
+ @Test
+ public void convertToPropertiesTest() throws Exception {
+ String testJson = "{\"prop2\"=\"value\", \"prop1\"=\"value\"}";
+ Map<String, String> response = JsonParser.convertToProperties(testJson);
+ assertEquals("value", response.get("prop2"));
+ }
+
+ @Test
+ public void convertToPropertiesTestwithArray() throws Exception {
+ String testJson = "{\"metadatum\": [{\"metaname\": \"remote-id\",\"metaval\": \"AC9.0234.0337\","
+ + "\"resource-version\": \"1553802421110\"},{\"metaname\": \"svlan\",\"metaval\": \"100\","
+ + "\"resource-version\": \"1553802421082\"}]}";
+ Map<String, String> response = JsonParser.convertToProperties(testJson);
+ assertEquals("100", response.get("metadatum[1].metaval"));
+ }
}
diff --git a/src/test/java/org/onap/dcae/controller/ConfigCBSSourceTest.java b/src/test/java/org/onap/dcae/controller/ConfigCbsSourceTest.java
index b34d393..2c42e9e 100644
--- a/src/test/java/org/onap/dcae/controller/ConfigCBSSourceTest.java
+++ b/src/test/java/org/onap/dcae/controller/ConfigCbsSourceTest.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.controller;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
@@ -33,21 +34,21 @@ import org.junit.Test;
import org.onap.dcae.WiremockBasedTest;
-public class ConfigCBSSourceTest extends WiremockBasedTest {
+public class ConfigCbsSourceTest extends WiremockBasedTest {
@Test
public void shouldReturnValidAppConfiguration() {
// given
- String sampleConfigForVES = "{\"collector.rcc.service.port\": 8080}";
+ String sampleConfigForVes = "{\"collector.rcc.service.port\": 8080}";
- stubConsulToReturnLocalAddressOfCBS();
- stubCBSToReturnAppConfig(sampleConfigForVES);
+ stubConsulToReturnLocalAddressOfCbs();
+ stubCbsToReturnAppConfig(sampleConfigForVes);
// when
Try<JSONObject> actual = tryToGetConfig();
// then
- assertThat(actual.get().toString()).isEqualTo(new JSONObject(sampleConfigForVES).toString());
+ assertThat(actual.get().toString()).isEqualTo(new JSONObject(sampleConfigForVes).toString());
}
@Test
@@ -115,10 +116,10 @@ public class ConfigCBSSourceTest extends WiremockBasedTest {
@Test
- public void shouldReturnFailureOnFailureToCommunicateWithCBS() {
+ public void shouldReturnFailureOnFailureToCommunicateWithCbs() {
// given
stubFor(get(urlEqualTo("/v1/catalog/service/CBSName"))
- .willReturn(aResponse().withStatus(200).withBody(validLocalCBSConf())));
+ .willReturn(aResponse().withStatus(200).withBody(validLocalCbsConf())));
stubFor(get(urlEqualTo("/service_component/restconfcollector"))
.willReturn(aResponse().withStatus(400)));
@@ -134,8 +135,8 @@ public class ConfigCBSSourceTest extends WiremockBasedTest {
public void shouldReturnFailureIfAppIsInvalidJsonDocument() {
// given
String invalidAppConf = "[$";
- stubConsulToReturnLocalAddressOfCBS();
- stubCBSToReturnAppConfig(invalidAppConf);
+ stubConsulToReturnLocalAddressOfCbs();
+ stubCbsToReturnAppConfig(invalidAppConf);
// when
Try<JSONObject> actual = tryToGetConfig();
@@ -145,7 +146,8 @@ public class ConfigCBSSourceTest extends WiremockBasedTest {
}
private Try<JSONObject> tryToGetConfig() {
- return getAppConfig(new EnvProps("http", "localhost", wireMockRule.port(), "http", "CBSName", "restconfcollector"));
+ return getAppConfig(new EnvProps("http", "localhost", wireMockRule.port(),
+ "http", "CBSName", "restconfcollector"));
}
}
diff --git a/src/test/java/org/onap/dcae/controller/ConfigFilesFacadeTest.java b/src/test/java/org/onap/dcae/controller/ConfigFilesFacadeTest.java
index 4130ceb..af87c30 100644
--- a/src/test/java/org/onap/dcae/controller/ConfigFilesFacadeTest.java
+++ b/src/test/java/org/onap/dcae/controller/ConfigFilesFacadeTest.java
@@ -19,16 +19,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.controller;
import static io.vavr.API.Map;
import static io.vavr.API.Some;
import static org.assertj.core.api.Assertions.assertThat;
import static org.onap.dcae.TestingUtilities.assertFailureHasInfo;
-import static org.onap.dcae.TestingUtilities.assertJSONObjectsEqual;
+import static org.onap.dcae.TestingUtilities.assertJsonObjectsEqual;
import static org.onap.dcae.TestingUtilities.createTemporaryFile;
import static org.onap.dcae.TestingUtilities.readFile;
-import static org.onap.dcae.TestingUtilities.readJSONFromFile;
+import static org.onap.dcae.TestingUtilities.readJsonFromFile;
import io.vavr.collection.Map;
import io.vavr.control.Try;
@@ -39,14 +40,14 @@ import org.junit.Test;
public class ConfigFilesFacadeTest {
- private static final Path NON_EXISTENT = Paths.get("/non-existent");
+ private static final Path NON_EXISTENT = Paths.get("/non-existent-file");
private static final ConfigFilesFacade TO_NON_EXISTENT_POINTING_FACADE = new ConfigFilesFacade(NON_EXISTENT,
NON_EXISTENT);
@Test
public void shouldReadPropertyFile() {
// given
- Path temporaryFile = createTemporaryFile("some.property=10");
+ Path temporaryFile = createTemporaryFile("temp_shouldReadPropertyFile","some.property=10");
// when
ConfigFilesFacade configFilesFacade = new ConfigFilesFacade(temporaryFile, temporaryFile);
@@ -63,22 +64,22 @@ public class ConfigFilesFacadeTest {
@Test
public void shouldReadDMaaPFile() {
// given
- Path temporaryFile = createTemporaryFile("{}");
+ Path temporaryFile = createTemporaryFile("temp_shouldReadDMaaPFile","{}");
// when
ConfigFilesFacade configFilesFacade = new ConfigFilesFacade(temporaryFile, temporaryFile);
- Try<JSONObject> dMaaPConfiguration = configFilesFacade.readDMaaPConfiguration();
+ Try<JSONObject> dmaapconfiguration = configFilesFacade.readDMaaPConfiguration();
// then
- assertThat(dMaaPConfiguration.isSuccess()).isTrue();
- assertThat(dMaaPConfiguration.get().toString()).isEqualTo("{}");
+ assertThat(dmaapconfiguration.isSuccess()).isTrue();
+ assertThat(dmaapconfiguration.get().toString()).isEqualTo("{}");
}
@Test
public void shouldWriteDMaaPConf() {
// given
- Path temporaryFile = createTemporaryFile("{}");
+ Path temporaryFile = createTemporaryFile("temp_shouldWriteDMaaPConf","{}");
JSONObject desiredConf = new JSONObject("{\"key\": 1}");
// when
@@ -88,14 +89,14 @@ public class ConfigFilesFacadeTest {
// then
assertThat(propertiesConfigurations.isSuccess()).isTrue();
- assertJSONObjectsEqual(readJSONFromFile(temporaryFile), desiredConf);
+ assertJsonObjectsEqual(readJsonFromFile(temporaryFile), desiredConf);
}
@Test
public void shouldWriteProperties() {
// given
- Path temporaryFile = createTemporaryFile("{}");
+ Path temporaryFile = createTemporaryFile("temp_shouldWriteProperties", "{}");
// when
ConfigFilesFacade configFilesFacade = new ConfigFilesFacade(temporaryFile, temporaryFile);
diff --git a/src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java b/src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java
index bcba7fb..be63b50 100644
--- a/src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java
+++ b/src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java
@@ -19,84 +19,58 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.controller;
import static io.vavr.API.Map;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyZeroInteractions;
import static org.onap.dcae.TestingUtilities.createTemporaryFile;
-import static org.onap.dcae.TestingUtilities.readFile;
-import static org.onap.dcae.TestingUtilities.readJSONFromFile;
+
+import static org.onap.dcae.TestingUtilities.readJsonFromFile;
import static org.onap.dcae.common.publishing.VavrUtils.f;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.json.JSONObject;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.dcae.ApplicationSettings;
-import org.onap.dcae.RestConfCollector;
import org.onap.dcae.WiremockBasedTest;
-import org.onap.dcae.common.publishing.DMaaPConfigurationParser;
import org.onap.dcae.common.publishing.EventPublisher;
public class ConfigLoaderIntegrationE2ETest extends WiremockBasedTest {
@Test
- public void testSuccessfulE2EFlow() {
-// // given
-// Path dMaaPConfigFile = createTemporaryFile("{}");
-// Path collectorPropertiesFile = createTemporaryFile("");
-// Path dMaaPConfigSource = Paths.get("src/test/resources/testParseDMaaPCredentialsGen2.json");
-// JSONObject dMaaPConf = readJSONFromFile(dMaaPConfigSource);
-// stubConsulToReturnLocalAddressOfCBS();
-// stubCBSToReturnAppConfig(f("{\"collector.port\": 8080, \"streams_publishes\": %s}}", dMaaPConf));
-//
-// EventPublisher eventPublisherMock = mock(EventPublisher.class);
-//
-// RestConfCollector rs = Mockito.mock(RestConfCollector.class);
-//
-//
-// ConfigFilesFacade configFilesFacade = new ConfigFilesFacade(dMaaPConfigFile, collectorPropertiesFile);
-// ConfigLoader configLoader = new ConfigLoader(eventPublisherMock::reconfigure, configFilesFacade, ConfigSource::getAppConfig, () -> wiremockBasedEnvProps());
-// configLoader.updateConfig();
-//
-// // then
-// assertThat(readJSONFromFile(dMaaPConfigSource).toString()).isEqualTo(dMaaPConf.toString());
-// assertThat(readFile(collectorPropertiesFile).trim()).isEqualTo("collector.port = 8080");
-// verify(eventPublisherMock, times(1)).reconfigure(
-// DMaaPConfigurationParser.parseToDomainMapping(dMaaPConf).get()
-// );
- }
-
- @Test
public void shouldNotReconfigureNotOverwriteIfConfigurationHasNotChanged() {
// given
- Path dMaaPConfigFile = createTemporaryFile("{}");
- Path collectorPropertiesFile = createTemporaryFile("");
- JSONObject dMaaPConf = readJSONFromFile(Paths.get("src/test/resources/testParseDMaaPCredentialsGen2.json"));
- stubConsulToReturnLocalAddressOfCBS();
- stubCBSToReturnAppConfig(f("{\"collector.port\": 8080, \"streams_publishes\": %s}}", dMaaPConf));
- EventPublisher eventPublisherMock = mock(EventPublisher.class);
- ConfigFilesFacade configFilesFacade = new ConfigFilesFacade(dMaaPConfigFile, collectorPropertiesFile);
- configFilesFacade.writeProperties(Map("collector.port", "8080"));
- configFilesFacade.writeDMaaPConfiguration(dMaaPConf);
-
- ConfigLoader configLoader = new ConfigLoader(eventPublisherMock::reconfigure, configFilesFacade, ConfigSource::getAppConfig, () -> wiremockBasedEnvProps());
- configLoader.updateConfig();
- // then
+ try {
+ Path dmaapConfigFile = createTemporaryFile("temp_dmaapConfigFile", "{}");
+ Path collectorPropertiesFile = createTemporaryFile("temp_collectorPropertiesFile", "");
+ JSONObject dmaapConf = readJsonFromFile(
+ Paths.get("src/test/resources/testParseDMaaPCredentialsGen2.json"));
+ stubConsulToReturnLocalAddressOfCbs();
+ stubCbsToReturnAppConfig(f("{\"collector.port\": 8080, \"streams_publishes\": %s}}", dmaapConf));
+ EventPublisher eventPublisherMock = mock(EventPublisher.class);
+ ConfigFilesFacade configFilesFacade = new ConfigFilesFacade(dmaapConfigFile, collectorPropertiesFile);
+ configFilesFacade.writeProperties(Map("collector.port", "8080"));
+ configFilesFacade.writeDMaaPConfiguration(dmaapConf);
- verifyZeroInteractions(eventPublisherMock);
+ ConfigLoader configLoader = new ConfigLoader(eventPublisherMock::reconfigure,
+ configFilesFacade, ConfigSource::getAppConfig, () -> wiremockBasedEnvProps());
+ configLoader.updateConfig();
+ // then
- // when
- JSONObject dMaaPConf2 = readJSONFromFile(Paths.get("src/test/resources/testParseDMaaPCredentialsGen2Temp.json"));
- configFilesFacade.writeDMaaPConfiguration(dMaaPConf2);
- configFilesFacade.writeProperties(Map("collector.port", "8081"));
- configLoader.updateConfig();
+ verifyZeroInteractions(eventPublisherMock);
+ // when
+ JSONObject dmaapConf2 = readJsonFromFile(
+ Paths.get("src/test/resources/testParseDMaaPCredentialsGen2Temp.json"));
+ configFilesFacade.writeDMaaPConfiguration(dmaapConf2);
+ configFilesFacade.writeProperties(Map("collector.port", "8081"));
+ configLoader.updateConfig();
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/controller/ConfigParsingTest.java b/src/test/java/org/onap/dcae/controller/ConfigParsingTest.java
index 7792b71..29c14e9 100644
--- a/src/test/java/org/onap/dcae/controller/ConfigParsingTest.java
+++ b/src/test/java/org/onap/dcae/controller/ConfigParsingTest.java
@@ -25,14 +25,11 @@ package org.onap.dcae.controller;
import static io.vavr.API.Map;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.onap.dcae.TestingUtilities.assertJSONObjectsEqual;
-import static org.onap.dcae.TestingUtilities.readJSONFromFile;
+import static org.onap.dcae.TestingUtilities.assertJsonObjectsEqual;
import io.vavr.collection.Map;
import io.vavr.control.Option;
-import java.nio.file.Path;
-import java.nio.file.Paths;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -43,16 +40,16 @@ public class ConfigParsingTest {
@Test
public void shouldReturnDMaaPConfig() {
- JSONObject dMaaPConf = new JSONObject("{\"auth-credentials-present\": {\"aaf_username\": \"sampleUser\",\"dmaap_info\": {\"topic_url\": \"http://UEBHOST:3904/events/DCAE-SE-COLLECTOR-EVENTS-DEV\",},\"aaf_password\": \"samplePassword\"}}");
+ JSONObject dmaapConf = new JSONObject("{\"auth-credentials-present\": {\"aaf_username\": \"sampleUser\",\"dmaap_info\": {\"topic_url\": \"http://UEBHOST:3904/events/DCAE-SE-COLLECTOR-EVENTS-DEV\",},\"aaf_password\": \"samplePassword\"}}");
JSONObject root = new JSONObject();
root.put("key1", "someProperty");
root.put("key2", "someProperty");
- root.put("streams_publishes", dMaaPConf);
+ root.put("streams_publishes", dmaapConf);
- Option<JSONObject> dMaaPConfig = ConfigParsing.getDMaaPConfig(root);
+ Option<JSONObject> dmaapConfig = ConfigParsing.getDMaaPConfig(root);
- assertThat(dMaaPConfig.isEmpty()).isFalse();
- assertJSONObjectsEqual(dMaaPConfig.get(), dMaaPConf);
+ assertThat(dmaapConfig.isEmpty()).isFalse();
+ assertJsonObjectsEqual(dmaapConfig.get(), dmaapConf);
}
@Test
@@ -60,18 +57,18 @@ public class ConfigParsingTest {
JSONObject root = new JSONObject();
root.put("streams_publishes", 1);
- Option<JSONObject> dMaaPConfig = ConfigParsing.getDMaaPConfig(root);
+ Option<JSONObject> dmaapConfig = ConfigParsing.getDMaaPConfig(root);
- assertThat(dMaaPConfig.isEmpty()).isTrue();
+ assertThat(dmaapConfig.isEmpty()).isTrue();
}
@Test
public void getProperties() {
- JSONObject dMaaPConf = new JSONObject("{\"auth-credentials-present\": {\"aaf_username\": \"sampleUser\",\"dmaap_info\": {\"topic_url\": \"http://UEBHOST:3904/events/DCAE-SE-COLLECTOR-EVENTS-DEV\",},\"aaf_password\": \"samplePassword\"}}");
+ JSONObject dmaapConf = new JSONObject("{\"auth-credentials-present\": {\"aaf_username\": \"sampleUser\",\"dmaap_info\": {\"topic_url\": \"http://UEBHOST:3904/events/DCAE-SE-COLLECTOR-EVENTS-DEV\",},\"aaf_password\": \"samplePassword\"}}");
JSONObject root = new JSONObject();
root.put("key1", "someProperty");
root.put("key2", "someProperty");
- root.put("streams_publishes", dMaaPConf);
+ root.put("streams_publishes", dmaapConf);
Map<String, String> properties = ConfigParsing.getProperties(root);
assertThat(properties).isEqualTo(Map("key1", "someProperty", "key2", "someProperty"));
diff --git a/src/test/java/org/onap/dcae/controller/EnvPropertiesReaderTest.java b/src/test/java/org/onap/dcae/controller/EnvPropertiesReaderTest.java
index 2e215a7..5fef321 100644
--- a/src/test/java/org/onap/dcae/controller/EnvPropertiesReaderTest.java
+++ b/src/test/java/org/onap/dcae/controller/EnvPropertiesReaderTest.java
@@ -19,6 +19,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.controller;
import static io.vavr.API.Map;
@@ -41,7 +42,7 @@ public class EnvPropertiesReaderTest {
}
@Test
- public void shouldReturnEmptyOnMissingCBSName() {
+ public void shouldReturnEmptyOnMissingCbsName() {
Map<String, String> envs = Map(
"CONSUL_HOST", "doesNotMatter",
"HOSTNAME", "doesNotMatter");
@@ -49,7 +50,7 @@ public class EnvPropertiesReaderTest {
}
@Test
- public void shouldReturnEmptyOnMissingVESAppName() {
+ public void shouldReturnEmptyOnMissingVesAppName() {
Map<String, String> envs = Map(
"CONSUL_HOST", "doesNotMatter",
"CONFIG_BINDING_SERVICE", "doesNotMatter");
diff --git a/src/test/java/org/onap/dcae/controller/EnvPropsTest.java b/src/test/java/org/onap/dcae/controller/EnvPropsTest.java
index e9c194e..1276e6b 100644
--- a/src/test/java/org/onap/dcae/controller/EnvPropsTest.java
+++ b/src/test/java/org/onap/dcae/controller/EnvPropsTest.java
@@ -20,22 +20,25 @@
package org.onap.dcae.controller;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+import static org.junit.Assert.assertEquals;
+
import com.github.tomakehurst.wiremock.junit.WireMockRule;
-import junit.framework.Assert;
import org.junit.Rule;
import org.junit.Test;
-import org.onap.dcae.common.Format;
-
-import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
-import static org.junit.Assert.assertEquals;
public class EnvPropsTest {
+
@Rule
public WireMockRule wireMockRule = new WireMockRule(
wireMockConfig().dynamicPort().dynamicHttpsPort().keystorePath(null));
+
@Test
public void fromString() {
- Assert.assertEquals(new EnvProps("http", "localhost", wireMockRule.port(), "http", "CBSName", "restconfcollector").equals(new EnvProps("http", "localhost", wireMockRule.port(), "http", "CBSName", "restconfcollector")), true);
+ assertEquals(new EnvProps("http", "localhost", wireMockRule.port(),
+ "http", "CBSName", "restconfcollector")
+ .equals(new EnvProps("http", "localhost", wireMockRule.port(),
+ "http", "CBSName", "restconfcollector")), true);
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/restapi/ApiAuthInterceptionTest.java b/src/test/java/org/onap/dcae/restapi/ApiAuthInterceptionTest.java
index 1427438..e8e911a 100644
--- a/src/test/java/org/onap/dcae/restapi/ApiAuthInterceptionTest.java
+++ b/src/test/java/org/onap/dcae/restapi/ApiAuthInterceptionTest.java
@@ -21,8 +21,19 @@
package org.onap.dcae.restapi;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import io.vavr.collection.HashMap;
import io.vavr.collection.Map;
+import java.io.IOException;
+import java.io.PrintWriter;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@@ -35,15 +46,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.PrintWriter;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.Silent.class)
public class ApiAuthInterceptionTest {