+ public void testApiStatisticsConstructorIsPrivate() {
+
+ try {
+ final Constructor<ApiStatisticsManager> constructor = ApiStatisticsManager.class.getDeclaredConstructor();
+ assertTrue(Modifier.isPrivate(constructor.getModifiers()));
+ constructor.setAccessible(true);
+ constructor.newInstance();
+ } catch (final Exception exp) {
+ assertTrue(exp.getCause().toString().contains("Instantiation of the class is not allowed"));
+ }
+ }
+
+ @Test
+ public void testCreatePolicyTypes() {
+ try {
+ main = startApiService(true);
+ for (String resrcName : toscaPolicyTypeResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertNotNull(response);
+ assertFalse(response.getPolicyTypes().isEmpty());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testCreatePolicies() {
+ try {
+ main = startApiService(true);
+ for (String resrcName : toscaPolicyResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, true);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
+ error.getErrorMessage());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testCreateGuardPolicies() {
+ try {
+ main = startApiService(true);
+ for (String resrcName : legacyGuardPolicyResourceNames) {
+ Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testCreateGuardPoliciesPersistent() {
+ try {
+ setupParameters(); // setup DB
+ main = startApiService(true);
+ for (String resrcName : legacyGuardPolicyResourceNames) {
+ Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testCreateOperationalPolicies() {
+ try {
+ main = startApiService(true);
+ for (String resrcName : legacyOperationalPolicyResourceNames) {
+ Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, true);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testCreateOperationalPoliciesPersistent() {
+ try {
+ setupParameters(); // setup DB
+ main = startApiService(true);
+ for (String resrcName : legacyOperationalPolicyResourceNames) {
+ Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, true);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testHttpsCreatePolicyTypes() {
+ try {
+ main = startApiService(false);
+ for (String resrcName : toscaPolicyTypeResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES, resrcName, false);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
+ assertNotNull(response);
+ assertFalse(response.getPolicyTypes().isEmpty());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testHttpsCreatePolicies() {
+ try {
+ main = startApiService(false);
+ for (String resrcName : toscaPolicyResourceNames) {
+ Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, false);
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
+ assertEquals("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
+ error.getErrorMessage());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testHttpsCreateGuardPolicies() {
+ try {
+ main = startApiService(false);
+ for (String resrcName : legacyGuardPolicyResourceNames) {
+ Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName, false);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testHttpsCreateOperationalPolicies() {
+ try {
+ main = startApiService(false);
+ for (String resrcName : legacyOperationalPolicyResourceNames) {
+ Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName, false);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+ }
+ } catch (Exception exp) {
+ fail("Test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testHealthCheckSuccessJson() {
+ testHealthCheckSuccess(APP_JSON);
+ }
+
+ @Test
+ public void testHealthCheckSuccessYaml() {
+ testHealthCheckSuccess(APP_YAML);
+ }
+
+
+
+ private void testHealthCheckSuccess(String mediaType) {