diff options
Diffstat (limited to 'policy-management/src/test/java/org')
4 files changed, 870 insertions, 761 deletions
diff --git a/policy-management/src/test/java/org/onap/policy/drools/persistence/test/SystemPersistenceTest.java b/policy-management/src/test/java/org/onap/policy/drools/persistence/test/SystemPersistenceTest.java index 788da053..56fab7fd 100644 --- a/policy-management/src/test/java/org/onap/policy/drools/persistence/test/SystemPersistenceTest.java +++ b/policy-management/src/test/java/org/onap/policy/drools/persistence/test/SystemPersistenceTest.java @@ -29,12 +29,13 @@ import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; import java.util.Properties; +import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.runners.MethodSorters; import org.onap.policy.drools.persistence.FileSystemPersistence; import org.onap.policy.drools.persistence.SystemPersistence; import org.onap.policy.drools.properties.PolicyProperties; @@ -44,6 +45,7 @@ import org.slf4j.LoggerFactory; /** * (File) System Persistence Tests */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class SystemPersistenceTest { /** @@ -59,7 +61,7 @@ public class SystemPersistenceTest { /** * Test JUnit Controller Name */ - public static final String TEST_CONTROLLER_NAME = "blue"; + public static final String TEST_CONTROLLER_NAME = "foo"; /** * Test JUnit Controller Name @@ -69,19 +71,27 @@ public class SystemPersistenceTest { /** * Test JUnit Controller Name Backup */ - public static final String TEST_CONTROLLER_FILE_BAK = - TEST_CONTROLLER_NAME + "-controller.properties.bak"; - + public static final String TEST_CONTROLLER_FILE_BAK = TEST_CONTROLLER_FILE + ".bak"; + /** * Test JUnit Environment/Engine properties */ private static final String ENV_PROPS = "envProps"; private static final String ENV_PROPS_FILE = ENV_PROPS + ".environment"; private static final String POLICY_ENGINE_PROPERTIES_FILE = "policy-engine.properties"; - + + @BeforeClass + public static void setUp() throws IOException { + cleanUpWorkingDirs(); + } + + @AfterClass + public static void tearDown() throws IOException { + cleanUpWorkingDirs(); + } @Test - public void nonDefaultConfigDir() throws IOException { + public void test1NonDefaultConfigDir() throws IOException { logger.info("enter"); SystemPersistence.manager.setConfigurationDir(OTHER_CONFIG_DIR); @@ -91,52 +101,44 @@ public class SystemPersistenceTest { SystemPersistence.manager.setConfigurationDir(null); assertTrue(SystemPersistence.manager.getConfigurationPath().toString() .equals(SystemPersistence.DEFAULT_CONFIGURATION_DIR)); - - this.engineConfiguration(); - this.persistConfiguration(); - - cleanUpWorkingDirs(); } - public void engineConfiguration() { + @Test + public void test2Engine() throws IOException { + logger.info("enter"); + SystemPersistence.manager.setConfigurationDir(OTHER_CONFIG_DIR); - final Path policyEnginePropsPath = Paths.get(OTHER_CONFIG_DIR + "/" + FileSystemPersistence.PROPERTIES_FILE_ENGINE); - final Path environmentPropertiesPath = Paths.get(OTHER_CONFIG_DIR + "/" + ENV_PROPS_FILE); - - Properties policyEnginePropsObject, emptyProps; - emptyProps = new Properties(); - - List<Properties> envPropertesList = new ArrayList<>(); - envPropertesList.add(emptyProps); - - policyEnginePropsObject = new Properties(); - policyEnginePropsObject.setProperty("foo", "bar"); - policyEnginePropsObject.setProperty("fiz", "buz"); - - try { - - if (Files.notExists(environmentPropertiesPath)) { - Files.createFile(environmentPropertiesPath); - } - - if (Files.notExists(policyEnginePropsPath)) { - OutputStream fout = new FileOutputStream(policyEnginePropsPath.toFile()); - policyEnginePropsObject.store(fout, ""); - fout.close(); - } - } catch (IOException e) { - logger.error("Problem creating {}", policyEnginePropsPath); + + final Path policyEnginePropsPath = + Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), + FileSystemPersistence.PROPERTIES_FILE_ENGINE); + + final Properties engineProps = new Properties(); + engineProps.setProperty("foo", "bar"); + engineProps.setProperty("fiz", "buz"); + if (Files.notExists(policyEnginePropsPath)) { + try (final OutputStream fout = new FileOutputStream(policyEnginePropsPath.toFile())) { + engineProps.store(fout, ""); + } } - - assertEquals(SystemPersistence.manager.getEngineProperties(), policyEnginePropsObject); - assertEquals(SystemPersistence.manager.getEnvironmentProperties(ENV_PROPS), emptyProps); - assertEquals(SystemPersistence.manager.getEnvironmentProperties(), envPropertesList); - + + assertEquals(SystemPersistence.manager.getEngineProperties(), engineProps); + + final Path environmentPropertiesPath = + Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), ENV_PROPS_FILE); + if (Files.notExists(environmentPropertiesPath)) { + Files.createFile(environmentPropertiesPath); + } + assertTrue(SystemPersistence.manager.getEnvironmentProperties(ENV_PROPS).isEmpty()); + assertTrue(SystemPersistence.manager.getEnvironmentProperties().size() == 1); } - - public void persistConfiguration() { + + @Test + public void test3PersistConfiguration() { logger.info("enter"); - + + SystemPersistence.manager.setConfigurationDir(null); + final Path controllerPath = Paths .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE); @@ -164,26 +166,22 @@ public class SystemPersistenceTest { assertTrue(Files.notExists(controllerPath)); } - @BeforeClass public static void cleanUpWorkingDirs() throws IOException { + + SystemPersistence.manager.setConfigurationDir(null); + final Path testControllerPath = Paths .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE); - final Path testControllerBakPath = Paths .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE_BAK); - final Path policyEnginePath = Paths - .get(OTHER_CONFIG_DIR + "/" + POLICY_ENGINE_PROPERTIES_FILE); - - final Path environmentPath = Paths - .get(OTHER_CONFIG_DIR + "/" + ENV_PROPS_FILE); - + final Path policyEnginePath = Paths.get(OTHER_CONFIG_DIR, POLICY_ENGINE_PROPERTIES_FILE); + final Path environmentPath = Paths.get(OTHER_CONFIG_DIR, ENV_PROPS_FILE); + Files.deleteIfExists(testControllerPath); Files.deleteIfExists(testControllerBakPath); Files.deleteIfExists(policyEnginePath); Files.deleteIfExists(environmentPath); - Files.deleteIfExists(Paths.get(OTHER_CONFIG_DIR)); - } } diff --git a/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.java b/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.java index 8ecda75d..f4c2410c 100644 --- a/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.java +++ b/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -29,80 +29,73 @@ import org.apache.commons.lang3.builder.HashCodeBuilder; import org.junit.Test; public class DroolsConfigurationTest { - private static final String ARTIFACT_ID_STRING = "artifactId"; - private static final String GROUP_ID_STRING = "groupId"; - private static final String VERSION_STRING = "version"; - - - private static final String NAME = "name"; - private static final String OPERATION = "operation"; - private static final String NAME2 = "name2"; - private static final String OPERATION2 = "operation2"; - - private static final String ARTIFACT = "org.onap.artifact"; - private static final String GROUPID = "group"; - private static final String VERSION = "1.0.0"; - - private static final String ARTIFACT2 = "org.onap.artifact2"; - private static final String GROUPID2 = "group2"; - private static final String VERSION2 = "1.0.1"; - - private static final String ADDITIONAL_PROPERTY_KEY = "foo"; - private static final String ADDITIONAL_PROPERTY_VALUE = "bar"; - - private static final DroolsConfiguration DROOLS_CONFIG = new DroolsConfiguration(ARTIFACT, GROUPID, VERSION); - private static final DroolsConfiguration DROOLS_CONFIG2 = new DroolsConfiguration(ARTIFACT2, GROUPID2, VERSION2); - - - - @Test - public void test() { - Properties additionalProperties = new Properties(); - additionalProperties.put(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE); - - DroolsConfiguration droolsConfig = new DroolsConfiguration(ARTIFACT, GROUPID, VERSION); - assertTrue(droolsConfig.equals(droolsConfig)); - - droolsConfig.set(ARTIFACT_ID_STRING, "foobar"); - assertEquals(droolsConfig.get(ARTIFACT_ID_STRING),"foobar"); - - assertEquals(droolsConfig.with(ARTIFACT_ID_STRING, "foobar2"), droolsConfig); - - DroolsConfiguration droolsConfig2 = new DroolsConfiguration(); - droolsConfig2.setArtifactId(ARTIFACT2); - droolsConfig2.setGroupId(GROUPID2); - droolsConfig2.setVersion(VERSION2); - - assertEquals(droolsConfig2.getArtifactId(), ARTIFACT2); - assertEquals(droolsConfig2.getGroupId(), GROUPID2); - assertEquals(droolsConfig2.getVersion(), VERSION2); - - assertEquals(droolsConfig2.withArtifactId(ARTIFACT2), droolsConfig2); - assertEquals(droolsConfig2.withGroupId(GROUPID2), droolsConfig2); - assertEquals(droolsConfig2.withVersion(VERSION2), droolsConfig2); - - droolsConfig2.setAdditionalProperty(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE); - assertEquals(droolsConfig2.getAdditionalProperties(), additionalProperties); - - assertEquals(droolsConfig2, droolsConfig2.withAdditionalProperty(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE)); - - assertTrue(droolsConfig2.declaredProperty(ARTIFACT_ID_STRING, ARTIFACT2)); - assertTrue(droolsConfig2.declaredProperty(GROUP_ID_STRING, GROUPID2)); - assertTrue(droolsConfig2.declaredProperty(VERSION_STRING, VERSION2)); - assertFalse(droolsConfig2.declaredProperty("dummy", NAME)); - - assertEquals(droolsConfig2.declaredPropertyOrNotFound(ARTIFACT_ID_STRING, ARTIFACT2), ARTIFACT2); - assertEquals(droolsConfig2.declaredPropertyOrNotFound(GROUP_ID_STRING, GROUPID2), GROUPID2); - assertEquals(droolsConfig2.declaredPropertyOrNotFound(VERSION_STRING, VERSION2), VERSION2); - assertEquals(droolsConfig2.declaredPropertyOrNotFound("dummy", ARTIFACT2), ARTIFACT2); - - int hashCode = new HashCodeBuilder().append(ARTIFACT2).append(GROUPID2).append(VERSION2).append(additionalProperties).toHashCode(); - assertEquals(droolsConfig2.hashCode(), hashCode); - - - - - } - - + private static final String ARTIFACT_ID_STRING = "artifactId"; + private static final String GROUP_ID_STRING = "groupId"; + private static final String VERSION_STRING = "version"; + + + private static final String NAME = "name"; + private static final String ARTIFACT = "org.onap.artifact"; + private static final String GROUPID = "group"; + private static final String VERSION = "1.0.0"; + + private static final String ARTIFACT2 = "org.onap.artifact2"; + private static final String GROUPID2 = "group2"; + private static final String VERSION2 = "1.0.1"; + + private static final String ADDITIONAL_PROPERTY_KEY = "foo"; + private static final String ADDITIONAL_PROPERTY_VALUE = "bar"; + + @Test + public void test() { + final Properties additionalProperties = new Properties(); + additionalProperties.put(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE); + + final DroolsConfiguration droolsConfig = new DroolsConfiguration(ARTIFACT, GROUPID, VERSION); + assertTrue(droolsConfig.equals(droolsConfig)); + + droolsConfig.set(ARTIFACT_ID_STRING, "foobar"); + assertEquals(droolsConfig.get(ARTIFACT_ID_STRING), "foobar"); + + assertEquals(droolsConfig.with(ARTIFACT_ID_STRING, "foobar2"), droolsConfig); + + final DroolsConfiguration droolsConfig2 = new DroolsConfiguration(); + droolsConfig2.setArtifactId(ARTIFACT2); + droolsConfig2.setGroupId(GROUPID2); + droolsConfig2.setVersion(VERSION2); + + assertEquals(droolsConfig2.getArtifactId(), ARTIFACT2); + assertEquals(droolsConfig2.getGroupId(), GROUPID2); + assertEquals(droolsConfig2.getVersion(), VERSION2); + + assertEquals(droolsConfig2.withArtifactId(ARTIFACT2), droolsConfig2); + assertEquals(droolsConfig2.withGroupId(GROUPID2), droolsConfig2); + assertEquals(droolsConfig2.withVersion(VERSION2), droolsConfig2); + + droolsConfig2.setAdditionalProperty(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE); + assertEquals(droolsConfig2.getAdditionalProperties(), additionalProperties); + + assertEquals(droolsConfig2, + droolsConfig2.withAdditionalProperty(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE)); + + assertTrue(droolsConfig2.declaredProperty(ARTIFACT_ID_STRING, ARTIFACT2)); + assertTrue(droolsConfig2.declaredProperty(GROUP_ID_STRING, GROUPID2)); + assertTrue(droolsConfig2.declaredProperty(VERSION_STRING, VERSION2)); + assertFalse(droolsConfig2.declaredProperty("dummy", NAME)); + + assertEquals(droolsConfig2.declaredPropertyOrNotFound(ARTIFACT_ID_STRING, ARTIFACT2), + ARTIFACT2); + assertEquals(droolsConfig2.declaredPropertyOrNotFound(GROUP_ID_STRING, GROUPID2), GROUPID2); + assertEquals(droolsConfig2.declaredPropertyOrNotFound(VERSION_STRING, VERSION2), VERSION2); + assertEquals(droolsConfig2.declaredPropertyOrNotFound("dummy", ARTIFACT2), ARTIFACT2); + + final int hashCode = new HashCodeBuilder().append(ARTIFACT2).append(GROUPID2).append(VERSION2) + .append(additionalProperties).toHashCode(); + assertEquals(droolsConfig2.hashCode(), hashCode); + + + + } + + } diff --git a/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java index 3a9f8a4b..e48c7954 100644 --- a/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java +++ b/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java @@ -21,20 +21,13 @@ package org.onap.policy.drools.server.restful.test; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Properties; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; -import org.onap.policy.drools.properties.PolicyProperties; -import org.onap.policy.drools.system.PolicyEngine; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.apache.http.HttpEntity; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; @@ -45,623 +38,743 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; +import org.onap.policy.drools.event.comm.TopicEndpoint; +import org.onap.policy.drools.persistence.SystemPersistence; +import org.onap.policy.drools.properties.PolicyProperties; +import org.onap.policy.drools.system.PolicyController; +import org.onap.policy.drools.system.PolicyEngine; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class RestManagerTest { - - - public static final int DEFAULT_TELEMETRY_PORT = 9698; - private static final String HOST = "localhost"; - private static final String REST_MANAGER_PATH = "/policy/pdp"; - private static final String HOST_URL = "http://" + HOST + ":" + DEFAULT_TELEMETRY_PORT + REST_MANAGER_PATH; - private static final String FOO_CONTROLLER = "foo-controller"; - - private static final String UEB_TOPIC = "PDPD-CONFIGURATION"; - private static final String DMAAP_TOPIC = "com.att.ecomp-policy.DCAE_CL_EVENT_TEST"; - private static final String NOOP_TOPIC = "NOOP_TOPIC"; - - private static final String UEB_SOURCE_SERVER_PROPERTY = PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS + - "." + UEB_TOPIC + PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX; - private static final String UEB_SINK_SERVER_PROPERTY = PolicyProperties.PROPERTY_UEB_SINK_TOPICS + - "." + UEB_TOPIC + PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX; - private static final String DMAAP_SOURCE_SERVER_PROPERTY = PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + - "." + DMAAP_TOPIC + PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX; - private static final String DMAAP_SINK_SERVER_PROPERTY = PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + - "." + DMAAP_TOPIC + PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX; - private static final String UEB_SERVER = "uebsb91sfdc.it.att.com"; - private static final String DMAAP_SERVER = "olsd005.wnsnet.attws.com"; - private static final String DMAAP_MECHID = "m03822@ecomp-policy.att.com"; - private static final String DMAAP_PASSWD = "Ec0mpP0l1cy"; - - private static final String DMAAP_SOURCE_MECHID_KEY = PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + - "." + DMAAP_TOPIC + PolicyProperties.PROPERTY_TOPIC_AAF_MECHID_SUFFIX; - private static final String DMAAP_SOURCE_PASSWD_KEY = PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + - "." + DMAAP_TOPIC + PolicyProperties.PROPERTY_TOPIC_AAF_PASSWORD_SUFFIX; - - private static final String DMAAP_SINK_MECHID_KEY = PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + - "." + DMAAP_TOPIC + PolicyProperties.PROPERTY_TOPIC_AAF_MECHID_SUFFIX; - private static final String DMAAP_SINK_PASSWD_KEY = PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + - "." + DMAAP_TOPIC + PolicyProperties.PROPERTY_TOPIC_AAF_PASSWORD_SUFFIX; - - - private static CloseableHttpClient client; - - private static final Logger logger = LoggerFactory.getLogger(RestManagerTest.class); - - @BeforeClass - public static void setUp() { - /* override default port */ - final Properties engineProps = PolicyEngine.manager.defaultTelemetryConfig(); - engineProps.put(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." - + PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME + PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX, - "" + DEFAULT_TELEMETRY_PORT); - engineProps.put(PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS, UEB_TOPIC); - engineProps.put(PolicyProperties.PROPERTY_UEB_SINK_TOPICS, UEB_TOPIC); - engineProps.put(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS, DMAAP_TOPIC); - engineProps.put(PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS, DMAAP_TOPIC); - engineProps.put(UEB_SOURCE_SERVER_PROPERTY, UEB_SERVER); - engineProps.put(UEB_SINK_SERVER_PROPERTY, UEB_SERVER); - engineProps.put(DMAAP_SOURCE_SERVER_PROPERTY, DMAAP_SERVER); - engineProps.put(DMAAP_SINK_SERVER_PROPERTY, DMAAP_SERVER); - engineProps.put(DMAAP_SOURCE_MECHID_KEY, DMAAP_MECHID); - engineProps.put(DMAAP_SOURCE_PASSWD_KEY, DMAAP_PASSWD); - engineProps.put(DMAAP_SINK_MECHID_KEY, DMAAP_MECHID); - engineProps.put(DMAAP_SINK_PASSWD_KEY, DMAAP_PASSWD); - engineProps.put(PolicyProperties.PROPERTY_NOOP_SINK_TOPICS, NOOP_TOPIC); - - - PolicyEngine.manager.configure(engineProps); - PolicyEngine.manager.start(); - - client = HttpClients.createDefault(); - - } - - @AfterClass - public static void tearDown() { - PolicyEngine.manager.shutdown(); + public static final int DEFAULT_TELEMETRY_PORT = 7887; + private static final String HOST = "localhost"; + private static final String REST_MANAGER_PATH = "/policy/pdp"; + private static final String HOST_URL = + "http://" + HOST + ":" + DEFAULT_TELEMETRY_PORT + REST_MANAGER_PATH; + private static final String FOO_CONTROLLER = "foo"; - } - - - @Test - public void putDeleteTest() throws ClientProtocolException, IOException, InterruptedException { - HttpPut httpPut; - HttpDelete httpDelete; - CloseableHttpResponse response; - - httpPut = new HttpPut(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/events"); - httpPut.addHeader("Content-Type", "text/plain"); - httpPut.addHeader("Accept", "application/json"); - httpPut.setEntity(new StringEntity("FOOOO")); - response = client.execute(httpPut); - logger.info("/engine/topics/sources/ueb/{}/events response code: {}", UEB_TOPIC, response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpPut.releaseConnection(); - - httpPut = new HttpPut(HOST_URL + "/engine/topics/switches/lock"); - response = client.execute(httpPut); - logger.info("/engine/topics/switches/lock response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpPut.releaseConnection(); - - httpPut = new HttpPut(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/events"); - httpPut.addHeader("Content-Type", "text/plain"); - httpPut.addHeader("Accept", "application/json"); - httpPut.setEntity(new StringEntity("FOOOO")); - response = client.execute(httpPut); - logger.info("/engine/topics/sources/ueb/{}/events response code: {}", UEB_TOPIC, response.getStatusLine().getStatusCode()); - assertEquals(406, response.getStatusLine().getStatusCode()); - httpPut.releaseConnection(); - - httpDelete = new HttpDelete(HOST_URL + "/engine/topics/switches/lock"); - response = client.execute(httpDelete); - logger.info("/engine/topics/switches/lock response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpDelete.releaseConnection(); - - httpPut = new HttpPut(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/switches/lock"); - response = client.execute(httpPut); - logger.info("/engine/topics/sources/ueb/{}/switches/lock: {}", UEB_TOPIC, response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpPut.releaseConnection(); - - httpDelete = new HttpDelete(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/switches/lock"); - response = client.execute(httpDelete); - logger.info("/engine/topics/sources/ueb/{}/switches/lock: {}", UEB_TOPIC, response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpDelete.releaseConnection(); - - httpPut = new HttpPut(HOST_URL + "/engine/topics/sources/dmaap/" + DMAAP_TOPIC + "/switches/lock"); - response = client.execute(httpPut); - logger.info("/engine/topics/sources/dmaap/{}/switches/lock: {}", DMAAP_TOPIC, response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpPut.releaseConnection(); - - httpDelete = new HttpDelete(HOST_URL + "/engine/topics/sources/dmaap/" + DMAAP_TOPIC + "/switches/lock"); - response = client.execute(httpDelete); - logger.info("/engine/topics/sources/dmaap/{}/switches/lock: {}", DMAAP_TOPIC, response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpDelete.releaseConnection(); - - httpPut = new HttpPut(HOST_URL + "/engine/switches/activation"); - response = client.execute(httpPut); - logger.info("/engine/switches/activation response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpPut.releaseConnection(); - - httpDelete = new HttpDelete(HOST_URL + "/engine/switches/activation"); - response = client.execute(httpDelete); - logger.info("/engine/switches/activation response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpDelete.releaseConnection(); + private static final String UEB_TOPIC = "UEB-TOPIC-TEST"; + private static final String DMAAP_TOPIC = "DMAAP-TOPIC-TEST"; + private static final String NOOP_TOPIC = "NOOP_TOPIC"; - } - - - @Test - public void getTest() throws ClientProtocolException, IOException, InterruptedException { - - HttpGet httpGet; - CloseableHttpResponse response; - String responseBody; - - httpGet = new HttpGet(HOST_URL + "/engine"); - response = client.execute(httpGet); - logger.info("/engine response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/features"); - response = client.execute(httpGet); - logger.info("/engine/features response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/features/inventory"); - response = client.execute(httpGet); - logger.info("/engine/features/inventory response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/features/foobar"); - response = client.execute(httpGet); - logger.info("/engine/features/foobar response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(404, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/inputs"); - response = client.execute(httpGet); - logger.info("/engine/inputs response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/properties"); - response = client.execute(httpGet); - logger.info("/engine/properties response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/environment"); - response = client.execute(httpGet); - logger.info("/engine/environment response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - PolicyEngine.manager.setEnvironmentProperty("foo", "bar"); - httpGet = new HttpGet(HOST_URL + "/engine/environment/foo"); - response = client.execute(httpGet); - responseBody = getResponseBody(response); - logger.info("/engine/environment/foo response code: {}",response.getStatusLine().getStatusCode()); - logger.info("/engine/environment/foo response body: {}",responseBody); - assertEquals(200, response.getStatusLine().getStatusCode()); - assertEquals("bar", responseBody); - httpGet.releaseConnection(); - - - httpGet = new HttpGet(HOST_URL + "/engine/switches"); - response = client.execute(httpGet); - logger.info("/engine/switches response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - - Properties controllerProps = new Properties(); - PolicyEngine.manager.createPolicyController(FOO_CONTROLLER, controllerProps); - httpGet = new HttpGet(HOST_URL + "/engine/controllers"); - response = client.execute(httpGet); - responseBody = getResponseBody(response); - logger.info("/engine/controllers response code: {}",response.getStatusLine().getStatusCode()); - logger.info("/engine/controllers response body: {}",responseBody); - assertEquals(200, response.getStatusLine().getStatusCode()); - assertEquals("[\"" + FOO_CONTROLLER +"\"]", responseBody); - httpGet.releaseConnection(); - - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/inventory"); - response = client.execute(httpGet); - logger.info("/engine/controllers/inventory response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/features"); - response = client.execute(httpGet); - logger.info("/engine/controllers/features response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/features/inventory"); - response = client.execute(httpGet); - logger.info("/engine/controllers/features/inventory response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/features/dummy"); - response = client.execute(httpGet); - logger.info("/engine/controllers/features/dummy response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(404, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER); - response = client.execute(httpGet); - logger.info("/engine/controllers/ response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller"); - response = client.execute(httpGet); - logger.info("/engine/controllers/nonexistantcontroller response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(404, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/properties"); - response = client.execute(httpGet); - responseBody = getResponseBody(response); - logger.info("/engine/controllers/contoller/properties response code: {}", response.getStatusLine().getStatusCode()); - logger.info("/engine/controllers/contoller/properties response code: {}", responseBody); - assertEquals(200, response.getStatusLine().getStatusCode()); - assertEquals("{}", responseBody); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller/properties"); - response = client.execute(httpGet); - logger.info("/engine/controllers/nonexistantcontroller/properties response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(404, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/inputs"); - response = client.execute(httpGet); - logger.info("/engine/controllers/controller/inputs response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/switches"); - response = client.execute(httpGet); - logger.info("/engine/controllers/controller/switches response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/drools"); - response = client.execute(httpGet); - logger.info("/engine/controllers/controller/drools response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller/drools"); - response = client.execute(httpGet); - logger.info("/engine/controllers/nonexistantcontroller/drools response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(404, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/drools/facts"); - response = client.execute(httpGet); - logger.info("/engine/controllers/controller/drools/facts response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller/drools/facts"); - response = client.execute(httpGet); - logger.info("/engine/controllers/nonexistantcontroller/drools/facts response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(404, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/drools/facts/dummy"); - response = client.execute(httpGet); - logger.info("/engine/controllers/controller/drools/facts/fact response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/drools/facts/dummy/dummy"); - response = client.execute(httpGet); - logger.info("/engine/controllers/controller/drools/facts/fact response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/drools/facts/session/query/queriedEntity"); - response = client.execute(httpGet); - logger.info("/engine/controllers/controller/drools/facts/session/query/queriedEntity response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders"); - response = client.execute(httpGet); - logger.info("/engine/controllers/controller/decoders response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller/decoders"); - response = client.execute(httpGet); - logger.info("/engine/controllers/nonexistantcontroller/decoders response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(404, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders/filters"); - response = client.execute(httpGet); - logger.info("/engine/controllers/controllers/decoders/filters response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller/decoders/filters"); - response = client.execute(httpGet); - logger.info("engine/controllers/nonexistantcontroller/decoders/filters response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(404, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders/topic"); - response = client.execute(httpGet); - logger.info("/engine/controllers/controllers/decoders/topics response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(404, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders/topic/filters"); - response = client.execute(httpGet); - logger.info("/engine/controllers/controllers/decoders/topic/filters response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(404, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders/topic/filters/factType"); - response = client.execute(httpGet); - logger.info("/engine/controllers/controller/decoders/topic/filters/factType response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(404, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders/topic/filters/factType/rules"); - response = client.execute(httpGet); - logger.info("/engine/controllers/controllers/decoders/topic/filters/factType/rules response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(404, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders/topic/filters/factType/rules/ruleName"); - response = client.execute(httpGet); - logger.info("/engine/controllers/controllers/decoders/topic/filters/factType/rules/ruleName response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(404, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/encoders"); - response = client.execute(httpGet); - logger.info("/engine/controllers/controller/encoders response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - - httpGet = new HttpGet(HOST_URL + "/engine/topics"); - response = client.execute(httpGet); - logger.info("/engine/topics response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/switches"); - response = client.execute(httpGet); - logger.info("/engine/topics/switches response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sources"); - response = client.execute(httpGet); - logger.info("/engine/topics/sources response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks"); - response = client.execute(httpGet); - logger.info("/engine/topics/sinks response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/ueb"); - response = client.execute(httpGet); - logger.info("/engine/topics/sinks/ueb response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/ueb"); - response = client.execute(httpGet); - logger.info("/engine/topics/sources/ueb response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/dmaap"); - response = client.execute(httpGet); - logger.info("/engine/topics/sources/dmaap response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/dmaap"); - response = client.execute(httpGet); - logger.info("/engine/topics/sinks/dmaap response code: {}",response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC); - response = client.execute(httpGet); - logger.info("engine/topics/sources/ueb/{} response code: {}", UEB_TOPIC,response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/ueb/foobar"); - response = client.execute(httpGet); - logger.info("engine/topics/sources/ueb/foobar response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(500, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/ueb/" + UEB_TOPIC); - response = client.execute(httpGet); - logger.info("engine/topics/sources/ueb/{} response code: {}", UEB_TOPIC,response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/ueb/foobar"); - response = client.execute(httpGet); - logger.info("engine/topics/sinks/ueb/foobar response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(500, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/dmaap/" + DMAAP_TOPIC); - response = client.execute(httpGet); - logger.info("engine/topics/sources/dmaap/{} response code: {}", DMAAP_TOPIC,response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/dmaap/foobar"); - response = client.execute(httpGet); - logger.info("engine/topics/sources/dmaap/foobar response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(500, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/dmaap/" + DMAAP_TOPIC); - response = client.execute(httpGet); - logger.info("engine/topics/sources/dmaap/{} response code: {}", DMAAP_TOPIC,response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/dmaap/foobar"); - response = client.execute(httpGet); - logger.info("engine/topics/sinks/dmaap/foobar response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(500, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/events"); - response = client.execute(httpGet); - logger.info("engine/topics/sources/ueb/{}/events response code: {}", UEB_TOPIC,response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/ueb/foobar/events"); - response = client.execute(httpGet); - logger.info("engine/topics/sources/ueb/foobar/events response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(500, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/ueb/" + UEB_TOPIC + "/events"); - response = client.execute(httpGet); - logger.info("engine/topics/sinks/ueb/{}/events response code: {}", UEB_TOPIC,response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/ueb/foobar/events"); - response = client.execute(httpGet); - logger.info("engine/topics/sinks/ueb/foobar/events response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(500, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/dmaap/" + DMAAP_TOPIC + "/events"); - response = client.execute(httpGet); - logger.info("engine/topics/sources/dmaap/{}/events response code: {}", DMAAP_TOPIC,response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/dmaap/foobar/events"); - response = client.execute(httpGet); - logger.info("engine/topics/sources/dmaap/foobar/events response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(500, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/dmaap/" + DMAAP_TOPIC + "/events"); - response = client.execute(httpGet); - logger.info("engine/topics/sinks/dmaap/{}/events response code: {}", DMAAP_TOPIC,response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/dmaap/foobar/events"); - response = client.execute(httpGet); - logger.info("engine/topics/sinks/dmaap/foobar/events response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(500, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/noop"); - response = client.execute(httpGet); - logger.info("engine/topics/sinks/noop response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/noop/" + NOOP_TOPIC); - response = client.execute(httpGet); - logger.info("engine/topics/sinks/noop/{} response code: {}", NOOP_TOPIC, response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/noop/" + NOOP_TOPIC + "/events"); - response = client.execute(httpGet); - logger.info("engine/topics/sinks/noop/{}/events response code: {}", NOOP_TOPIC, response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/switches"); - response = client.execute(httpGet); - logger.info("engine/topics/sources/ueb/{}/switches response code: {}", UEB_TOPIC, response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/dmaap/" + DMAAP_TOPIC + "/switches"); - response = client.execute(httpGet); - logger.info("engine/topics/sources/dmaap/{}/switches response code: {}", DMAAP_TOPIC, response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/tools/uuid"); - response = client.execute(httpGet); - logger.info("engine/tools/uuid response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/tools/loggers"); - response = client.execute(httpGet); - logger.info("engine/tools/loggers response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - httpGet = new HttpGet(HOST_URL + "/engine/tools/loggers/ROOT"); - response = client.execute(httpGet); - logger.info("engine/tools/loggers/ROOT response code: {}", response.getStatusLine().getStatusCode()); - assertEquals(200, response.getStatusLine().getStatusCode()); - httpGet.releaseConnection(); - - } + private static final String UEB_SOURCE_SERVER_PROPERTY = + PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS + "." + UEB_TOPIC + + PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX; + private static final String UEB_SINK_SERVER_PROPERTY = PolicyProperties.PROPERTY_UEB_SINK_TOPICS + + "." + UEB_TOPIC + PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX; + private static final String DMAAP_SOURCE_SERVER_PROPERTY = + PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "." + DMAAP_TOPIC + + PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX; + private static final String DMAAP_SINK_SERVER_PROPERTY = + PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + "." + DMAAP_TOPIC + + PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX; + private static final String UEB_SERVER = "localhost"; + private static final String DMAAP_SERVER = "localhost"; + private static final String DMAAP_MECHID = "blah"; + private static final String DMAAP_PASSWD = "blah"; + + private static final String DMAAP_SOURCE_MECHID_KEY = + PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "." + DMAAP_TOPIC + + PolicyProperties.PROPERTY_TOPIC_AAF_MECHID_SUFFIX; + private static final String DMAAP_SOURCE_PASSWD_KEY = + PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "." + DMAAP_TOPIC + + PolicyProperties.PROPERTY_TOPIC_AAF_PASSWORD_SUFFIX; + + private static final String DMAAP_SINK_MECHID_KEY = PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + + "." + DMAAP_TOPIC + PolicyProperties.PROPERTY_TOPIC_AAF_MECHID_SUFFIX; + private static final String DMAAP_SINK_PASSWD_KEY = PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + + "." + DMAAP_TOPIC + PolicyProperties.PROPERTY_TOPIC_AAF_PASSWORD_SUFFIX; + + + private static final String FOO_CONTROLLER_FILE = FOO_CONTROLLER + "-controller.properties"; + private static final String FOO_CONTROLLER_FILE_BAK = FOO_CONTROLLER_FILE + ".bak"; + + private static CloseableHttpClient client; + + private static final Logger logger = LoggerFactory.getLogger(RestManagerTest.class); + + @BeforeClass + public static void setUp() throws IOException { + cleanUpWorkingDirs(); + + SystemPersistence.manager.setConfigurationDir(null); + + /* override default port */ + final Properties engineProps = PolicyEngine.manager.defaultTelemetryConfig(); + engineProps.put(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + + PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME + PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX, + "" + DEFAULT_TELEMETRY_PORT); + + /* other properties */ + engineProps.put(PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS, UEB_TOPIC); + engineProps.put(PolicyProperties.PROPERTY_UEB_SINK_TOPICS, UEB_TOPIC); + engineProps.put(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS, DMAAP_TOPIC); + engineProps.put(PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS, DMAAP_TOPIC); + engineProps.put(UEB_SOURCE_SERVER_PROPERTY, UEB_SERVER); + engineProps.put(UEB_SINK_SERVER_PROPERTY, UEB_SERVER); + engineProps.put(DMAAP_SOURCE_SERVER_PROPERTY, DMAAP_SERVER); + engineProps.put(DMAAP_SINK_SERVER_PROPERTY, DMAAP_SERVER); + engineProps.put(DMAAP_SOURCE_MECHID_KEY, DMAAP_MECHID); + engineProps.put(DMAAP_SOURCE_PASSWD_KEY, DMAAP_PASSWD); + engineProps.put(DMAAP_SINK_MECHID_KEY, DMAAP_MECHID); + engineProps.put(DMAAP_SINK_PASSWD_KEY, DMAAP_PASSWD); + engineProps.put(PolicyProperties.PROPERTY_NOOP_SINK_TOPICS, NOOP_TOPIC); + + PolicyEngine.manager.configure(engineProps); + PolicyEngine.manager.start(); + + client = HttpClients.createDefault(); + } + + @AfterClass + public static void tearDown() throws IOException, InterruptedException { + /* Shutdown managed resources */ + PolicyController.factory.shutdown(); + TopicEndpoint.manager.shutdown(); + PolicyEngine.manager.stop(); + Thread.sleep(10000L); + client.close(); + cleanUpWorkingDirs(); + } + + @Test + public void putDeleteTest() throws ClientProtocolException, IOException, InterruptedException { + HttpPut httpPut; + HttpDelete httpDelete; + CloseableHttpResponse response; + + httpPut = new HttpPut(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/events"); + httpPut.addHeader("Content-Type", "text/plain"); + httpPut.addHeader("Accept", "application/json"); + httpPut.setEntity(new StringEntity("FOOOO")); + response = client.execute(httpPut); + logger.info("/engine/topics/sources/ueb/{}/events response code: {}", UEB_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpPut.releaseConnection(); + + httpPut = new HttpPut(HOST_URL + "/engine/topics/switches/lock"); + response = client.execute(httpPut); + logger.info("/engine/topics/switches/lock response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpPut.releaseConnection(); + + httpPut = new HttpPut(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/events"); + httpPut.addHeader("Content-Type", "text/plain"); + httpPut.addHeader("Accept", "application/json"); + httpPut.setEntity(new StringEntity("FOOOO")); + response = client.execute(httpPut); + logger.info("/engine/topics/sources/ueb/{}/events response code: {}", UEB_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(406, response.getStatusLine().getStatusCode()); + httpPut.releaseConnection(); + + httpDelete = new HttpDelete(HOST_URL + "/engine/topics/switches/lock"); + response = client.execute(httpDelete); + logger.info("/engine/topics/switches/lock response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpDelete.releaseConnection(); + + httpPut = new HttpPut(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/switches/lock"); + response = client.execute(httpPut); + logger.info("/engine/topics/sources/ueb/{}/switches/lock: {}", UEB_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpPut.releaseConnection(); + + httpDelete = + new HttpDelete(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/switches/lock"); + response = client.execute(httpDelete); + logger.info("/engine/topics/sources/ueb/{}/switches/lock: {}", UEB_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpDelete.releaseConnection(); + + httpPut = + new HttpPut(HOST_URL + "/engine/topics/sources/dmaap/" + DMAAP_TOPIC + "/switches/lock"); + response = client.execute(httpPut); + logger.info("/engine/topics/sources/dmaap/{}/switches/lock: {}", DMAAP_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpPut.releaseConnection(); + + httpDelete = + new HttpDelete(HOST_URL + "/engine/topics/sources/dmaap/" + DMAAP_TOPIC + "/switches/lock"); + response = client.execute(httpDelete); + logger.info("/engine/topics/sources/dmaap/{}/switches/lock: {}", DMAAP_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpDelete.releaseConnection(); + + httpDelete = new HttpDelete(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER); + response = client.execute(httpDelete); + logger.info(httpDelete.getRequestLine() + " response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpDelete.releaseConnection(); + + httpPut = new HttpPut(HOST_URL + "/engine/switches/activation"); + response = client.execute(httpPut); + logger.info("/engine/switches/activation response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpPut.releaseConnection(); + + httpDelete = new HttpDelete(HOST_URL + "/engine/switches/activation"); + response = client.execute(httpDelete); + logger.info("/engine/switches/activation response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpDelete.releaseConnection(); + + httpPut = new HttpPut(HOST_URL + "/engine/switches/lock"); + response = client.execute(httpPut); + logger.info("/engine/switches/activation response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpPut.releaseConnection(); + + httpDelete = new HttpDelete(HOST_URL + "/engine/switches/lock"); + response = client.execute(httpDelete); + logger.info("/engine/switches/lock response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpPut.releaseConnection(); + } + + @Test + public void getTest() throws ClientProtocolException, IOException, InterruptedException { + + HttpGet httpGet; + CloseableHttpResponse response; + String responseBody; + + httpGet = new HttpGet(HOST_URL + "/engine"); + response = client.execute(httpGet); + logger.info("/engine response code: {}", response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/features"); + response = client.execute(httpGet); + logger.info("/engine/features response code: {}", response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/features/inventory"); + response = client.execute(httpGet); + logger.info("/engine/features/inventory response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/features/foobar"); + response = client.execute(httpGet); + logger.info("/engine/features/foobar response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(404, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/inputs"); + response = client.execute(httpGet); + logger.info("/engine/inputs response code: {}", response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/properties"); + response = client.execute(httpGet); + logger.info("/engine/properties response code: {}", response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/environment"); + response = client.execute(httpGet); + logger.info("/engine/environment response code: {}", response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + PolicyEngine.manager.setEnvironmentProperty("foo", "bar"); + httpGet = new HttpGet(HOST_URL + "/engine/environment/foo"); + response = client.execute(httpGet); + responseBody = this.getResponseBody(response); + logger.info("/engine/environment/foo response code: {}", + response.getStatusLine().getStatusCode()); + logger.info("/engine/environment/foo response body: {}", responseBody); + assertEquals(200, response.getStatusLine().getStatusCode()); + assertEquals("bar", responseBody); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/switches"); + response = client.execute(httpGet); + logger.info("/engine/switches response code: {}", response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + final Properties controllerProps = new Properties(); + PolicyEngine.manager.createPolicyController(FOO_CONTROLLER, controllerProps); + httpGet = new HttpGet(HOST_URL + "/engine/controllers"); + response = client.execute(httpGet); + responseBody = this.getResponseBody(response); + logger.info("/engine/controllers response code: {}", response.getStatusLine().getStatusCode()); + logger.info("/engine/controllers response body: {}", responseBody); + assertEquals(200, response.getStatusLine().getStatusCode()); + assertEquals("[\"" + FOO_CONTROLLER + "\"]", responseBody); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/inventory"); + response = client.execute(httpGet); + logger.info("/engine/controllers/inventory response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/features"); + response = client.execute(httpGet); + logger.info("/engine/controllers/features response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/features/inventory"); + response = client.execute(httpGet); + logger.info("/engine/controllers/features/inventory response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + httpGet = new HttpGet(HOST_URL + "/engine/controllers/features/dummy"); + response = client.execute(httpGet); + logger.info("/engine/controllers/features/dummy response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(404, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER); + response = client.execute(httpGet); + logger.info("/engine/controllers/ response code: {}", response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller"); + response = client.execute(httpGet); + logger.info("/engine/controllers/nonexistantcontroller response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(404, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/properties"); + response = client.execute(httpGet); + responseBody = this.getResponseBody(response); + logger.info("/engine/controllers/contoller/properties response code: {}", + response.getStatusLine().getStatusCode()); + logger.info("/engine/controllers/contoller/properties response code: {}", responseBody); + assertEquals(200, response.getStatusLine().getStatusCode()); + assertEquals("{}", responseBody); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller/properties"); + response = client.execute(httpGet); + logger.info("/engine/controllers/nonexistantcontroller/properties response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(404, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/inputs"); + response = client.execute(httpGet); + logger.info("/engine/controllers/controller/inputs response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/switches"); + response = client.execute(httpGet); + logger.info("/engine/controllers/controller/switches response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/drools"); + response = client.execute(httpGet); + logger.info("/engine/controllers/controller/drools response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller/drools"); + response = client.execute(httpGet); + logger.info("/engine/controllers/nonexistantcontroller/drools response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(404, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/drools/facts"); + response = client.execute(httpGet); + logger.info("/engine/controllers/controller/drools/facts response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller/drools/facts"); + response = client.execute(httpGet); + logger.info("/engine/controllers/nonexistantcontroller/drools/facts response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(404, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = + new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/drools/facts/dummy"); + response = client.execute(httpGet); + logger.info("/engine/controllers/controller/drools/facts/fact response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet( + HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/drools/facts/dummy/dummy"); + response = client.execute(httpGet); + logger.info("/engine/controllers/controller/drools/facts/fact response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + + "/drools/facts/session/query/queriedEntity"); + response = client.execute(httpGet); + logger.info( + "/engine/controllers/controller/drools/facts/session/query/queriedEntity response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders"); + response = client.execute(httpGet); + logger.info("/engine/controllers/controller/decoders response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller/decoders"); + response = client.execute(httpGet); + logger.info("/engine/controllers/nonexistantcontroller/decoders response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(404, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders/filters"); + response = client.execute(httpGet); + logger.info("/engine/controllers/controllers/decoders/filters response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller/decoders/filters"); + response = client.execute(httpGet); + logger.info("engine/controllers/nonexistantcontroller/decoders/filters response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(404, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders/topic"); + response = client.execute(httpGet); + logger.info("/engine/controllers/controllers/decoders/topics response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(404, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = + new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders/topic/filters"); + response = client.execute(httpGet); + logger.info("/engine/controllers/controllers/decoders/topic/filters response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(404, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet( + HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders/topic/filters/factType"); + response = client.execute(httpGet); + logger.info("/engine/controllers/controller/decoders/topic/filters/factType response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(404, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + + "/decoders/topic/filters/factType/rules"); + response = client.execute(httpGet); + logger.info( + "/engine/controllers/controllers/decoders/topic/filters/factType/rules response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(404, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + + "/decoders/topic/filters/factType/rules/ruleName"); + response = client.execute(httpGet); + logger.info( + "/engine/controllers/controllers/decoders/topic/filters/factType/rules/ruleName response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(404, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/encoders"); + response = client.execute(httpGet); + logger.info("/engine/controllers/controller/encoders response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics"); + response = client.execute(httpGet); + logger.info("/engine/topics response code: {}", response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/switches"); + response = client.execute(httpGet); + logger.info("/engine/topics/switches response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sources"); + response = client.execute(httpGet); + logger.info("/engine/topics/sources response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks"); + response = client.execute(httpGet); + logger.info("/engine/topics/sinks response code: {}", response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/ueb"); + response = client.execute(httpGet); + logger.info("/engine/topics/sinks/ueb response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/ueb"); + response = client.execute(httpGet); + logger.info("/engine/topics/sources/ueb response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/dmaap"); + response = client.execute(httpGet); + logger.info("/engine/topics/sources/dmaap response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/dmaap"); + response = client.execute(httpGet); + logger.info("/engine/topics/sinks/dmaap response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC); + response = client.execute(httpGet); + logger.info("engine/topics/sources/ueb/{} response code: {}", UEB_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/ueb/foobar"); + response = client.execute(httpGet); + logger.info("engine/topics/sources/ueb/foobar response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(500, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/ueb/" + UEB_TOPIC); + response = client.execute(httpGet); + logger.info("engine/topics/sources/ueb/{} response code: {}", UEB_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/ueb/foobar"); + response = client.execute(httpGet); + logger.info("engine/topics/sinks/ueb/foobar response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(500, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/dmaap/" + DMAAP_TOPIC); + response = client.execute(httpGet); + logger.info("engine/topics/sources/dmaap/{} response code: {}", DMAAP_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/dmaap/foobar"); + response = client.execute(httpGet); + logger.info("engine/topics/sources/dmaap/foobar response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(500, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/dmaap/" + DMAAP_TOPIC); + response = client.execute(httpGet); + logger.info("engine/topics/sources/dmaap/{} response code: {}", DMAAP_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/dmaap/foobar"); + response = client.execute(httpGet); + logger.info("engine/topics/sinks/dmaap/foobar response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(500, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/events"); + response = client.execute(httpGet); + logger.info("engine/topics/sources/ueb/{}/events response code: {}", UEB_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/ueb/foobar/events"); + response = client.execute(httpGet); + logger.info("engine/topics/sources/ueb/foobar/events response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(500, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/ueb/" + UEB_TOPIC + "/events"); + response = client.execute(httpGet); + logger.info("engine/topics/sinks/ueb/{}/events response code: {}", UEB_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/ueb/foobar/events"); + response = client.execute(httpGet); + logger.info("engine/topics/sinks/ueb/foobar/events response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(500, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/dmaap/" + DMAAP_TOPIC + "/events"); + response = client.execute(httpGet); + logger.info("engine/topics/sources/dmaap/{}/events response code: {}", DMAAP_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/dmaap/foobar/events"); + response = client.execute(httpGet); + logger.info("engine/topics/sources/dmaap/foobar/events response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(500, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/dmaap/" + DMAAP_TOPIC + "/events"); + response = client.execute(httpGet); + logger.info("engine/topics/sinks/dmaap/{}/events response code: {}", DMAAP_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/dmaap/foobar/events"); + response = client.execute(httpGet); + logger.info("engine/topics/sinks/dmaap/foobar/events response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(500, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/noop"); + response = client.execute(httpGet); + logger.info("engine/topics/sinks/noop response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/noop/" + NOOP_TOPIC); + response = client.execute(httpGet); + logger.info("engine/topics/sinks/noop/{} response code: {}", NOOP_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sinks/noop/" + NOOP_TOPIC + "/events"); + response = client.execute(httpGet); + logger.info("engine/topics/sinks/noop/{}/events response code: {}", NOOP_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/switches"); + response = client.execute(httpGet); + logger.info("engine/topics/sources/ueb/{}/switches response code: {}", UEB_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/topics/sources/dmaap/" + DMAAP_TOPIC + "/switches"); + response = client.execute(httpGet); + logger.info("engine/topics/sources/dmaap/{}/switches response code: {}", DMAAP_TOPIC, + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/tools/uuid"); + response = client.execute(httpGet); + logger.info("engine/tools/uuid response code: {}", response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/tools/loggers"); + response = client.execute(httpGet); + logger.info("engine/tools/loggers response code: {}", response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + + httpGet = new HttpGet(HOST_URL + "/engine/tools/loggers/ROOT"); + response = client.execute(httpGet); + logger.info("engine/tools/loggers/ROOT response code: {}", + response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); + httpGet.releaseConnection(); + } + + + public String getResponseBody(CloseableHttpResponse response) { + + HttpEntity entity; + try { + entity = response.getEntity(); + return EntityUtils.toString(entity); + + } catch (final IOException e) { - public String getResponseBody(CloseableHttpResponse response) { - - HttpEntity entity; - try { - entity = response.getEntity(); - return EntityUtils.toString(entity); - - } catch (IOException e) { - - } - - return null; } - + + return null; + } + + private static void cleanUpWorkingDirs() throws IOException { + final Path testControllerPath = + Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), FOO_CONTROLLER_FILE); + final Path testControllerBakPath = Paths + .get(SystemPersistence.manager.getConfigurationPath().toString(), FOO_CONTROLLER_FILE_BAK); + + Files.deleteIfExists(testControllerPath); + Files.deleteIfExists(testControllerBakPath); + } + } diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/test/PolicyEngineTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/test/PolicyEngineTest.java index 5ab6c580..9d52bc5c 100644 --- a/policy-management/src/test/java/org/onap/policy/drools/system/test/PolicyEngineTest.java +++ b/policy-management/src/test/java/org/onap/policy/drools/system/test/PolicyEngineTest.java @@ -33,6 +33,7 @@ import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; +import org.onap.policy.drools.event.comm.TopicEndpoint; import org.onap.policy.drools.persistence.SystemPersistence; import org.onap.policy.drools.properties.PolicyProperties; import org.onap.policy.drools.system.PolicyController; @@ -54,7 +55,7 @@ public class PolicyEngineTest { /** * Test JUnit Controller Name */ - public static final String TEST_CONTROLLER_NAME = "unnamed"; + public static final String TEST_CONTROLLER_NAME = "foo"; /** * Controller Configuration File @@ -64,8 +65,7 @@ public class PolicyEngineTest { /** * Controller Configuration Backup File */ - public static final String TEST_CONTROLLER_FILE_BAK = - TEST_CONTROLLER_NAME + "-controller.properties.bak"; + public static final String TEST_CONTROLLER_FILE_BAK = TEST_CONTROLLER_FILE + ".bak"; /** * logger @@ -226,10 +226,15 @@ public class PolicyEngineTest { } @Test - public void test901Stop() { + public void test901Stop() throws InterruptedException { logger.info("enter"); + /* Shutdown managed resources */ + PolicyController.factory.shutdown(); + TopicEndpoint.manager.shutdown(); PolicyEngine.manager.stop(); + + Thread.sleep(10000L); assertFalse(PolicyEngine.manager.isAlive()); } |