From 5a6a6de6f1a26a1897e4917a0df613e25a24eb70 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Mon, 30 Jul 2018 15:56:09 -0400 Subject: Containerization feature of SO Change-Id: I95381232eeefcd247a66a5cec370a8ce1c288e18 Issue-ID: SO-670 Signed-off-by: Benjamin, Max (mb388a) --- common/src/test/java/org/onap/so/BeansTest.java | 97 ++++ .../onap/so/adapter_utils/tests/CryptoTest.java | 83 +++ .../so/adapter_utils/tests/MsoAlarmLoggerTest.java | 134 +++++ .../onap/so/adapter_utils/tests/MsoLoggerTest.java | 331 +++++++++++ .../java/org/onap/so/client/RestClientTest.java | 87 +++ .../aai/AAIClientResponseExceptionMapperTest.java | 70 +++ .../so/client/aai/AAIConfigurationClientTest.java | 181 ++++++ .../onap/so/client/aai/AAIErrorFormatterTest.java | 88 +++ .../org/onap/so/client/aai/AAIObjectTypeTest.java | 55 ++ .../org/onap/so/client/aai/AAIPServerTest.java | 57 ++ .../org/onap/so/client/aai/AAIQueryClientTest.java | 93 ++++ .../onap/so/client/aai/AAIResourcesClientTest.java | 191 +++++++ .../org/onap/so/client/aai/AAIRestClientTest.java | 124 +++++ .../so/client/aai/AAITransactionalClientTest.java | 148 +++++ .../java/org/onap/so/client/aai/AAIURITest.java | 44 ++ .../org/onap/so/client/aai/AAIUpdatorImplTest.java | 53 ++ .../org/onap/so/client/aai/AAIUpdatorTest.java | 61 ++ .../org/onap/so/client/aai/AAIValidatorTest.java | 98 ++++ .../client/aai/entities/AAIResultWrapperTest.java | 94 ++++ .../so/client/aai/entities/RelationshipsTest.java | 61 ++ .../aai/entities/uri/AAISimpleUriFromUriTest.java | 60 ++ .../client/aai/entities/uri/AAISimpleUriTest.java | 78 +++ .../client/aai/entities/uri/AAIUriFactoryTest.java | 68 +++ .../aai/entities/uri/ServiceInstanceUriTest.java | 192 +++++++ .../aai/objects/AAIOperationalEnvironmentTest.java | 55 ++ .../client/aai/objects/AAIServiceInstanceTest.java | 53 ++ .../DefaultAAIPropertiesImpl.java | 78 +++ .../org/onap/so/client/dmaap/DmaapClientTest.java | 41 ++ .../onap/so/client/dmaap/DmaapPublisherTest.java | 60 ++ .../uri/parsers/UriParserSpringImplTest.java | 49 ++ .../GraphInventoryPayloadExceptionTest.java | 40 ++ .../java/org/onap/so/client/grm/GRMBeansTest.java | 62 +++ .../java/org/onap/so/client/grm/GRMClientTest.java | 217 ++++++++ .../so/client/grm/ServiceEndPointListTest.java | 75 +++ .../so/client/grm/ServiceEndPointRequestTest.java | 90 +++ .../so/client/policy/PolicyClientImplTest.java | 111 ++++ .../client/policy/entities/PolicyEntitiesTest.java | 59 ++ .../onap/so/client/ruby/RubyCheckClientTest.java | 106 ++++ .../onap/so/client/ruby/beans/RubyBeansTest.java | 59 ++ .../so/client/sdno/SDNOHealthCheckClientTest.java | 94 ++++ .../org/onap/so/client/sdno/SDNOValidatorTest.java | 116 ++++ .../onap/so/client/sdno/beans/SdnoBeansTest.java | 59 ++ .../java/org/onap/so/entity/MsoRequestTest.java | 64 +++ .../so/exceptions/ValidationExceptionTest.java | 53 ++ .../org/onap/so/jsonpath/JsonPathUtilTest.java | 55 ++ .../ServiceInstanceBeansTest.java | 64 +++ .../ServiceInstancesRequestTest.java | 44 ++ .../java/org/onap/so/utils/CheckResultsTest.java | 58 ++ .../test/java/org/onap/so/utils/TestAppender.java | 41 ++ .../java/org/onap/so/utils/UUIDCheckerTest.java | 60 ++ .../java/org/onap/so/utils/XMLMarshallerTest.java | 101 ++++ .../web/exceptions/RuntimeExceptionMapperTest.java | 71 +++ .../mso/adapter_utils/tests/CryptoTest.java | 79 --- .../adapter_utils/tests/MsoAlarmLoggerTest.java | 131 ----- .../mso/adapter_utils/tests/MsoLoggerTest.java | 331 ----------- .../tests/MsoPropertiesFactoryConcurrencyTest.java | 174 ------ .../tests/MsoPropertiesFactoryTest.java | 611 --------------------- .../tests/MsoPropertyInitializerTest.java | 88 --- .../mso/client/aai/AAIConfigurationTest.java | 75 --- .../mso/client/aai/AAIExceptionMapperTest.java | 63 --- .../mso/client/aai/AAIObjectTypeTest.java | 39 -- .../openecomp/mso/client/aai/AAIPServerTest.java | 57 -- .../mso/client/aai/AAIResourcesClientTest.java | 111 ---- .../mso/client/aai/AAITransactionalClientTest.java | 83 --- .../org/openecomp/mso/client/aai/AAIURITest.java | 44 -- .../mso/client/aai/AAIUpdatorImplTest.java | 53 -- .../openecomp/mso/client/aai/AAIValidatorTest.java | 98 ---- .../mso/client/aai/entities/RelationshipsTest.java | 61 -- .../client/aai/entities/uri/AAIUriFactoryTest.java | 40 -- .../aai/entities/uri/ServiceInstanceUriTest.java | 194 ------- .../aai/entities/uri/SimpleUriFromUriTest.java | 59 -- .../mso/client/aai/entities/uri/SimpleUriTest.java | 69 --- .../uri/parsers/UriParserSpringImplTest.java | 47 -- .../aai/exceptions/AAIPayloadExceptionTest.java | 39 -- .../aai/objects/AAIOperationalEnvironmentTest.java | 55 -- .../client/aai/objects/AAIOwningEntityTest.java | 40 -- .../mso/client/aai/objects/AAIProjectTest.java | 41 -- .../client/aai/objects/AAIServiceInstanceTest.java | 53 -- .../mso/client/dmaap/DmaapClientTest.java | 41 -- .../mso/client/dmaap/DmaapPublisherTest.java | 60 -- .../org/openecomp/mso/client/grm/GRMBeansTest.java | 62 --- .../openecomp/mso/client/grm/GRMClientTest.java | 185 ------- .../mso/client/grm/ServiceEndPointListTest.java | 75 --- .../mso/client/grm/ServiceEndPointRequestTest.java | 90 --- .../mso/client/policy/PolicyClientImplTest.java | 104 ---- .../client/policy/entities/PolicyEntitiesTest.java | 59 -- .../mso/client/ruby/RubyCheckClientTest.java | 106 ---- .../mso/client/ruby/beans/RubyBeansTest.java | 59 -- .../mso/client/sdno/SDNOHealthCheckClientTest.java | 94 ---- .../mso/client/sdno/SDNOValidatorTest.java | 116 ---- .../mso/client/sdno/beans/SdnoBeansTest.java | 59 -- .../org/openecomp/mso/entity/MsoRequestTest.java | 64 --- .../openecomp/mso/jsonpath/JsonPathUtilTest.java | 49 -- .../ServiceInstanceBeansTest.java | 64 --- .../ServiceInstancesRequestTest.java | 44 -- .../org/openecomp/mso/utils/CheckResultsTest.java | 56 -- .../mso/utils/RootIgnoringObjectMapperTest.java | 94 ---- .../org/openecomp/mso/utils/UUIDCheckerTest.java | 44 -- .../aai/bulkprocess/test-request-small.json | 10 + .../__files/aai/resources/e2e-complex.json | 78 +-- .../resources/service-instance-pathed-query.json | 2 +- .../src/test/resources/__files/grm/endpoints.json | 6 +- common/src/test/resources/dmaap.properties | 4 +- common/src/test/resources/logback-test.xml | 39 +- common/src/test/resources/mso-bad.json | 38 +- .../ruby/create-ticket/create-ticket-request.json | 15 + .../custom-lport-mirror-post-check-request.json | 27 + .../custom-lport-mirror-pre-check-request.json | 27 + .../custom-port-mirror-post-check-request.json | 23 + .../custom-port-mirror-pre-check-request.json | 23 + .../org/onap/so/client/sdno/output-failure.json | 25 + .../org/onap/so/client/sdno/output-success.json | 22 + .../org/onap/so/client/sdno/response.json | 17 + .../ruby/create-ticket/create-ticket-request.json | 15 - .../custom-lport-mirror-post-check-request.json | 26 - .../custom-lport-mirror-pre-check-request.json | 26 - .../custom-port-mirror-post-check-request.json | 22 - .../custom-port-mirror-pre-check-request.json | 22 - .../openecomp/mso/client/sdno/output-failure.json | 25 - .../openecomp/mso/client/sdno/output-success.json | 22 - .../org/openecomp/mso/client/sdno/response.json | 17 - 121 files changed, 4858 insertions(+), 4516 deletions(-) create mode 100644 common/src/test/java/org/onap/so/BeansTest.java create mode 100644 common/src/test/java/org/onap/so/adapter_utils/tests/CryptoTest.java create mode 100644 common/src/test/java/org/onap/so/adapter_utils/tests/MsoAlarmLoggerTest.java create mode 100644 common/src/test/java/org/onap/so/adapter_utils/tests/MsoLoggerTest.java create mode 100644 common/src/test/java/org/onap/so/client/RestClientTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/AAIClientResponseExceptionMapperTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/AAIConfigurationClientTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/AAIErrorFormatterTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/AAIPServerTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/AAIURITest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/AAIUpdatorImplTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/AAIUpdatorTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/objects/AAIOperationalEnvironmentTest.java create mode 100644 common/src/test/java/org/onap/so/client/aai/objects/AAIServiceInstanceTest.java create mode 100644 common/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java create mode 100644 common/src/test/java/org/onap/so/client/dmaap/DmaapClientTest.java create mode 100644 common/src/test/java/org/onap/so/client/dmaap/DmaapPublisherTest.java create mode 100644 common/src/test/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java create mode 100644 common/src/test/java/org/onap/so/client/graphinventory/exceptions/GraphInventoryPayloadExceptionTest.java create mode 100644 common/src/test/java/org/onap/so/client/grm/GRMBeansTest.java create mode 100644 common/src/test/java/org/onap/so/client/grm/GRMClientTest.java create mode 100644 common/src/test/java/org/onap/so/client/grm/ServiceEndPointListTest.java create mode 100644 common/src/test/java/org/onap/so/client/grm/ServiceEndPointRequestTest.java create mode 100644 common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java create mode 100644 common/src/test/java/org/onap/so/client/policy/entities/PolicyEntitiesTest.java create mode 100644 common/src/test/java/org/onap/so/client/ruby/RubyCheckClientTest.java create mode 100644 common/src/test/java/org/onap/so/client/ruby/beans/RubyBeansTest.java create mode 100644 common/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java create mode 100644 common/src/test/java/org/onap/so/client/sdno/SDNOValidatorTest.java create mode 100644 common/src/test/java/org/onap/so/client/sdno/beans/SdnoBeansTest.java create mode 100644 common/src/test/java/org/onap/so/entity/MsoRequestTest.java create mode 100644 common/src/test/java/org/onap/so/exceptions/ValidationExceptionTest.java create mode 100644 common/src/test/java/org/onap/so/jsonpath/JsonPathUtilTest.java create mode 100644 common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstanceBeansTest.java create mode 100644 common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstancesRequestTest.java create mode 100644 common/src/test/java/org/onap/so/utils/CheckResultsTest.java create mode 100644 common/src/test/java/org/onap/so/utils/TestAppender.java create mode 100644 common/src/test/java/org/onap/so/utils/UUIDCheckerTest.java create mode 100644 common/src/test/java/org/onap/so/utils/XMLMarshallerTest.java create mode 100644 common/src/test/java/org/onap/so/web/exceptions/RuntimeExceptionMapperTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/adapter_utils/tests/CryptoTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoAlarmLoggerTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryConcurrencyTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertyInitializerTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/AAIConfigurationTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/AAIExceptionMapperTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/AAIObjectTypeTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/AAIPServerTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/AAIResourcesClientTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/AAITransactionalClientTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/AAIURITest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/AAIUpdatorImplTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/AAIValidatorTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/entities/RelationshipsTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/entities/uri/AAIUriFactoryTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/entities/uri/ServiceInstanceUriTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/entities/uri/SimpleUriFromUriTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/entities/uri/SimpleUriTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/entities/uri/parsers/UriParserSpringImplTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/exceptions/AAIPayloadExceptionTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/objects/AAIOperationalEnvironmentTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/objects/AAIOwningEntityTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/objects/AAIProjectTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/aai/objects/AAIServiceInstanceTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/dmaap/DmaapClientTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/dmaap/DmaapPublisherTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/grm/GRMBeansTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/grm/GRMClientTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/grm/ServiceEndPointListTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/grm/ServiceEndPointRequestTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/policy/PolicyClientImplTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/policy/entities/PolicyEntitiesTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/ruby/RubyCheckClientTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/ruby/beans/RubyBeansTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/sdno/SDNOHealthCheckClientTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/sdno/SDNOValidatorTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/client/sdno/beans/SdnoBeansTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/entity/MsoRequestTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/jsonpath/JsonPathUtilTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/serviceinstancebeans/ServiceInstanceBeansTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/serviceinstancebeans/ServiceInstancesRequestTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/utils/CheckResultsTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/utils/RootIgnoringObjectMapperTest.java delete mode 100644 common/src/test/java/org/openecomp/mso/utils/UUIDCheckerTest.java create mode 100644 common/src/test/resources/__files/aai/bulkprocess/test-request-small.json create mode 100644 common/src/test/resources/org/onap/so/client/ruby/create-ticket/create-ticket-request.json create mode 100644 common/src/test/resources/org/onap/so/client/sdno/health-check/custom-lport-mirror-post-check-request.json create mode 100644 common/src/test/resources/org/onap/so/client/sdno/health-check/custom-lport-mirror-pre-check-request.json create mode 100644 common/src/test/resources/org/onap/so/client/sdno/health-check/custom-port-mirror-post-check-request.json create mode 100644 common/src/test/resources/org/onap/so/client/sdno/health-check/custom-port-mirror-pre-check-request.json create mode 100644 common/src/test/resources/org/onap/so/client/sdno/output-failure.json create mode 100644 common/src/test/resources/org/onap/so/client/sdno/output-success.json create mode 100644 common/src/test/resources/org/onap/so/client/sdno/response.json delete mode 100644 common/src/test/resources/org/openecomp/mso/client/ruby/create-ticket/create-ticket-request.json delete mode 100644 common/src/test/resources/org/openecomp/mso/client/sdno/health-check/custom-lport-mirror-post-check-request.json delete mode 100644 common/src/test/resources/org/openecomp/mso/client/sdno/health-check/custom-lport-mirror-pre-check-request.json delete mode 100644 common/src/test/resources/org/openecomp/mso/client/sdno/health-check/custom-port-mirror-post-check-request.json delete mode 100644 common/src/test/resources/org/openecomp/mso/client/sdno/health-check/custom-port-mirror-pre-check-request.json delete mode 100644 common/src/test/resources/org/openecomp/mso/client/sdno/output-failure.json delete mode 100644 common/src/test/resources/org/openecomp/mso/client/sdno/output-success.json delete mode 100644 common/src/test/resources/org/openecomp/mso/client/sdno/response.json (limited to 'common/src/test') diff --git a/common/src/test/java/org/onap/so/BeansTest.java b/common/src/test/java/org/onap/so/BeansTest.java new file mode 100644 index 0000000000..2e825cf8c7 --- /dev/null +++ b/common/src/test/java/org/onap/so/BeansTest.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so; + +import static org.hamcrest.CoreMatchers.allOf; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.onap.so.openpojo.rules.HasAnnotationMatcher.hasAnnotation; +import static org.onap.so.openpojo.rules.HasAnnotationPropertyWithValueMatcher.hasAnnotationPropertyWithValue; + +import javax.persistence.Column; +import javax.persistence.Temporal; + +import org.junit.Test; +import org.onap.so.openpojo.rules.CustomSetterMustExistRule; +import org.onap.so.openpojo.rules.EqualsAndHashCodeTester; +import org.onap.so.openpojo.rules.HasEqualsAndHashCodeRule; +import org.onap.so.openpojo.rules.HasToStringRule; +import org.onap.so.openpojo.rules.ToStringTester; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.PojoClassFilter; +import com.openpojo.reflection.filters.FilterEnum; +import com.openpojo.reflection.filters.FilterNonConcrete; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.BusinessKeyMustExistRule; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.NoNestedClassRule; +import com.openpojo.validation.rule.impl.NoPrimitivesRule; +import com.openpojo.validation.rule.impl.NoPublicFieldsExceptStaticFinalRule; +import com.openpojo.validation.rule.impl.NoStaticExceptFinalRule; +import com.openpojo.validation.rule.impl.SerializableMustHaveSerialVersionUIDRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + + +public class BeansTest { + + private PojoClassFilter filterTestClasses = new FilterTestClasses(); + + private PojoClassFilter enumFilter = new FilterEnum(); + + + + @Test + public void pojoStructure() { + test("org.onap.so.client.aai.objects"); + test("org.onap.so.client.policy.entities"); + test("org.onap.so.client.grm.beans"); + test("org.onap.so.client.ruby.beans"); + test("org.onap.so.client.sdno.beans"); + test("org.onap.so.entity"); + test("org.onap.so.serviceinstancebeans"); + } + + private void test(String pojoPackage) { + Validator validator = ValidatorBuilder.create() + .with(new GetterMustExistRule()) + .with(new NoNestedClassRule()) + .with(new NoStaticExceptFinalRule()) + .with(new SerializableMustHaveSerialVersionUIDRule()) + .with(new NoPublicFieldsExceptStaticFinalRule()) + .with(new SetterTester()) + .with(new GetterTester()) + + + + .build(); + + + validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses,enumFilter,new FilterNonConcrete()); + } + private static class FilterTestClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.getSourcePath().contains("/test-classes/"); + } + } +} diff --git a/common/src/test/java/org/onap/so/adapter_utils/tests/CryptoTest.java b/common/src/test/java/org/onap/so/adapter_utils/tests/CryptoTest.java new file mode 100644 index 0000000000..15368f9966 --- /dev/null +++ b/common/src/test/java/org/onap/so/adapter_utils/tests/CryptoTest.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapter_utils.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.security.GeneralSecurityException; + +import org.junit.BeforeClass; +import org.junit.Test; + +import org.onap.so.utils.CryptoUtils; + +/** + * This class implements all test methods of the CryptoUtils features. + * + * + */ +public class CryptoTest { + + private static String testKey = "546573746F736973546573746F736973"; + + /** + * This method is called before any test occurs. + * It creates a fake tree from scratch + */ + @BeforeClass + public static final void prepare () { + + } + + /** + * This method implements a test of tree structure, mainly the storage of the leaves structure. + * @throws GeneralSecurityException + */ + @Test + public final void testEncryption () throws GeneralSecurityException { + String hexString = CryptoUtils.byteArrayToHexString("testosistestosi".getBytes()); + + final String testData = "This is a test string"; + final String nonTestData = "This is not the right String"; + + String encodeString = CryptoUtils.encrypt(testData, testKey); + + assertNotNull(encodeString); + + assertTrue(testData.equals(CryptoUtils.decrypt(encodeString, testKey))); + assertFalse(nonTestData.equals(CryptoUtils.decrypt(encodeString, testKey))); + + String encode2String = CryptoUtils.encrypt(testData, testKey); + assertNotNull(encode2String); + + assertEquals(encodeString,encode2String); + + assertEquals(CryptoUtils.decrypt(encodeString, testKey),CryptoUtils.decrypt(encode2String, testKey)); + + encodeString = CryptoUtils.encryptCloudConfigPassword(testData); + + assertEquals(testData, CryptoUtils.decryptCloudConfigPassword(encodeString)); + } + +} diff --git a/common/src/test/java/org/onap/so/adapter_utils/tests/MsoAlarmLoggerTest.java b/common/src/test/java/org/onap/so/adapter_utils/tests/MsoAlarmLoggerTest.java new file mode 100644 index 0000000000..6756bc98ad --- /dev/null +++ b/common/src/test/java/org/onap/so/adapter_utils/tests/MsoAlarmLoggerTest.java @@ -0,0 +1,134 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapter_utils.tests; + + +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.so.logger.MsoAlarmLogger; + + +/** + * This junit test very roughly the alarm logger + * + */ +public class MsoAlarmLoggerTest { + + public static MsoAlarmLogger msoAlarmLogger; + + @BeforeClass + public static final void createObjects() throws IOException + { + + File outputFile = new File ("./target/alarm-test.log"); + if (outputFile.exists()) { + outputFile.delete(); + } else { + outputFile.createNewFile(); + } + msoAlarmLogger = new MsoAlarmLogger("./target/alarm-test.log"); + } + + @AfterClass + public static void tearDown() { + msoAlarmLogger.resetAppender(); + } + @Test + public void testAlarmConfig() throws IOException { + + msoAlarmLogger.sendAlarm("test", 0, "detail message"); + + FileInputStream inputStream = new FileInputStream("./target/alarm-test.log"); + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); + + String line = reader.readLine(); + String[] splitLine = line.split("\\|"); + assertTrue(splitLine.length==4); + assertTrue("test".equals(splitLine[1])); + assertTrue("0".equals(splitLine[2])); + assertTrue("detail message".equals(splitLine[3])); + + line = reader.readLine(); + assertNull(line); + reader.close(); + inputStream.close(); + + // Reset the file for others tests + PrintWriter writer = new PrintWriter(new File("./target/alarm-test.log")); + writer.print(""); + writer.close(); + + } + + @Test + public void testAlarm() throws IOException { + + msoAlarmLogger.sendAlarm("test", 0, "detail message"); + msoAlarmLogger.sendAlarm("test2", 1, "detail message2"); + msoAlarmLogger.sendAlarm("test3", 2, "detail message3"); + + FileInputStream inputStream = new FileInputStream("./target/alarm-test.log"); + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); + + String line = reader.readLine(); + String[] splitLine = line.split("\\|"); + assertTrue(splitLine.length==4); + assertTrue("test".equals(splitLine[1])); + assertTrue("0".equals(splitLine[2])); + assertTrue("detail message".equals(splitLine[3])); + + line = reader.readLine(); + splitLine = line.split("\\|"); + assertTrue(splitLine.length==4); + assertTrue("test2".equals(splitLine[1])); + assertTrue("1".equals(splitLine[2])); + assertTrue("detail message2".equals(splitLine[3])); + + line = reader.readLine(); + splitLine = line.split("\\|"); + assertTrue(splitLine.length==4); + assertTrue("test3".equals(splitLine[1])); + assertTrue("2".equals(splitLine[2])); + assertTrue("detail message3".equals(splitLine[3])); + + line = reader.readLine(); + assertNull(line); + reader.close(); + inputStream.close(); + + // Reset the file for others tests + PrintWriter writer = new PrintWriter(new File("./target/alarm-test.log")); + writer.print(""); + writer.close(); + + } +} diff --git a/common/src/test/java/org/onap/so/adapter_utils/tests/MsoLoggerTest.java b/common/src/test/java/org/onap/so/adapter_utils/tests/MsoLoggerTest.java new file mode 100644 index 0000000000..29ac91c864 --- /dev/null +++ b/common/src/test/java/org/onap/so/adapter_utils/tests/MsoLoggerTest.java @@ -0,0 +1,331 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapter_utils.tests; + +import org.onap.so.entity.MsoRequest; +import org.onap.so.logger.MessageEnum; +import org.onap.so.logger.MsoLogger; +import org.onap.so.logger.MsoLogger.ErrorCode; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.MDC; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URL; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +/** + * This class implements all test methods of the MsoLogger features. + * + * + */ +public class MsoLoggerTest { + + static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL, MsoLoggerTest.class); + + /** + * This method is called before any test occurs. It creates a fake tree from + * scratch + */ + @BeforeClass + public static final void prepare() { + + } + + @Before + public final void cleanErrorLogFile() throws FileNotFoundException { + URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); + String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + + "/MSO/Test/errorjboss.server.name_IS_UNDEFINED.log"; + PrintWriter asdcConfigFileWriter = new PrintWriter(logFile); + asdcConfigFileWriter.print(""); + asdcConfigFileWriter.flush(); + asdcConfigFileWriter.close(); + } + + @Before + public final void cleanMetricLogFile() throws FileNotFoundException { + URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); + String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + + "/MSO/Test/metricsjboss.server.name_IS_UNDEFINED.log"; + PrintWriter asdcConfigFileWriter = new PrintWriter(logFile); + asdcConfigFileWriter.print(""); + asdcConfigFileWriter.flush(); + asdcConfigFileWriter.close(); + } + + @Before + public final void cleanAuditLogFile() throws FileNotFoundException { + URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); + String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + + "/MSO/Test/auditjbo.server.name_IS_UNDEFINED.log"; + PrintWriter asdcConfigFileWriter = new PrintWriter(logFile); + asdcConfigFileWriter.print(""); + asdcConfigFileWriter.flush(); + asdcConfigFileWriter.close(); + } + + /** + * This method implements a test of getSeverifyLevel method. + */ + @Test + public final void testGetSeverityLevel() { + + try { + String levelInfo = (String) invokePriveMethod("getSeverityLevel", "INFO"); + Assert.assertEquals(levelInfo, "0"); + + String levelWarn = (String) invokePriveMethod("getSeverityLevel", "WARN"); + Assert.assertEquals(levelWarn, "1"); + + String levelERROR = (String) invokePriveMethod("getSeverityLevel", "ERROR"); + Assert.assertEquals(levelERROR, "2"); + + String levelDEBUG = (String) invokePriveMethod("getSeverityLevel", "DEBUG"); + Assert.assertEquals(levelDEBUG, "0"); + + String levelFATAL = (String) invokePriveMethod("getSeverityLevel", "FATAL"); + Assert.assertEquals(levelFATAL, "3"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * This method implements a test of getFinalServiceName method. + */ + @Test + public final void testGetFinalServiceName() { + try { + String serviceName1 = (String) invokePriveMethod("getFinalServiceName", "testServiceName1"); + Assert.assertEquals(serviceName1, "testServiceName1"); + + MsoLogger.setServiceName("testServiceName2"); + String serviceName2 = (String) invokePriveMethod("getFinalServiceName", "testServiceName1"); + Assert.assertEquals(serviceName2, "testServiceName1"); + + String msgNull = null; + String serviceName3 = (String) invokePriveMethod("getFinalServiceName", msgNull); + Assert.assertEquals(serviceName3, "testServiceName2"); + + MsoLogger.resetServiceName(); + String serviceName4 = (String) invokePriveMethod("getFinalServiceName", msgNull); + Assert.assertEquals(serviceName4, "invoke0"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public final void testPrepareMsg() { + try { + String msgNull = null; + MDC.clear(); + invokePrepareMsg("INFO", null, null); + + Assert.assertTrue(MDC.get(MsoLogger.REQUEST_ID).equals("trace-#") + && MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("trace-#") + && MDC.get(MsoLogger.SERVICE_NAME).equals("invoke0") && MDC.get(MsoLogger.TIMER) == null + && MDC.get(MsoLogger.ALERT_SEVERITY).equals("0")); + + MsoLogger.setLoggerParameters("testRemoteIp", "testUser"); + MsoLogger.setLogContext("testReqId", "testSvcId"); + invokePrepareMsg("ERROR", "testServiceName3", null); + Assert.assertTrue(MDC.get(MsoLogger.REQUEST_ID).equals("testReqId") + && MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("testSvcId") + && MDC.get(MsoLogger.SERVICE_NAME).equals("testServiceName3") && MDC.get(MsoLogger.TIMER) == null + && MDC.get(MsoLogger.ALERT_SEVERITY).equals("2")); + + MsoLogger.setServiceName("testServiceName2"); + invokePrepareMsg("WARN", msgNull, msgNull); + Assert.assertTrue(MDC.get(MsoLogger.REQUEST_ID).equals("testReqId") + && MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("testSvcId") + && MDC.get(MsoLogger.SERVICE_NAME).equals("testServiceName2") && MDC.get(MsoLogger.TIMER) == null + && MDC.get(MsoLogger.ALERT_SEVERITY).equals("1")); + + MDC.clear(); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("reqId2"); + msoRequest.setServiceInstanceId("servId2"); + MsoLogger.setLogContext(msoRequest); + invokePrepareMsg("FATAL", null, "123"); + Assert.assertTrue(MDC.get(MsoLogger.REQUEST_ID).equals("reqId2") + && MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("servId2") + && MDC.get(MsoLogger.TIMER).equals("123") && MDC.get(MsoLogger.ALERT_SEVERITY).equals("3")); + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * This method implements a test of log methods + */ + @Test + @Ignore + public final void testLogMethods() { + try { + MDC.clear(); + MsoLogger.setLogContext("reqId2", "servId2"); + MsoLogger.setServiceName("MSO.testServiceName"); + msoLogger.info(MessageEnum.LOGGER_UPDATE_SUC, "testLogger", "INFO", "DEBUG", "target entity", + "target service"); + msoLogger.warn(MessageEnum.GENERAL_WARNING, "warning test", "", "", MsoLogger.ErrorCode.UnknownError, + "warning test"); + msoLogger.error(MessageEnum.GENERAL_EXCEPTION, "target entity", "target service", + MsoLogger.ErrorCode.UnknownError, "error test"); + + // Fetch from the error log + URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); + String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + + "/MSO/Test/errorjboss.server.name_IS_UNDEFINED.log"; + + Path filePath = new File(logFile).toPath(); + Charset charset = Charset.defaultCharset(); + List stringList = Files.readAllLines(filePath, charset); + String[] stringArray = stringList.toArray(new String[] {}); + int size = stringArray.length; + + Assert.assertTrue(stringArray[size - 3] + .contains("|reqId2|main|MSO.testServiceName||target entity|target service|INFO|null||") + && stringArray[size - 3].contains( + "||MSO-GENERAL-5408I Successfully update Logger: testLogger from level INFO to level DEBUG")); + Assert.assertTrue(stringArray[size - 2] + .contains("|reqId2|main|MSO.testServiceName||||WARN|UnknownError|warning test|") + && stringArray[size - 2].contains("|MSO-GENERAL-5401W WARNING: warning test")); + Assert.assertTrue(stringArray[size - 1].contains( + "|reqId2|main|MSO.testServiceName||target entity|target service|ERROR|UnknownError|error test|") + && stringArray[size - 1].contains("|MSO-GENERAL-9401E Exception encountered")); + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * This method implements a test of recordMetricEvent method. + * + * @throws IOException + */ + @Test + @Ignore + public final void testRecordMetricEvent() throws IOException { + MDC.clear(); + MsoLogger.setLogContext("reqId", "servId"); + msoLogger.recordMetricEvent(123456789L, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful", + "VNF", "createVNF", null); + MDC.put(MsoLogger.REMOTE_HOST, "127.0.0.1"); + MDC.put(MsoLogger.PARTNERNAME, "testUser"); + msoLogger.recordMetricEvent(123456789L, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.ServiceNotAvailable, + "Exception", "SDNC", "removeSDNC", "testVNF"); + + // Fetch from the metric log + URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); + String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + + "/MSO/Test/metricsjboss.server.name_IS_UNDEFINED.log"; + + Path filePath = new File(logFile).toPath(); + Charset charset = Charset.defaultCharset(); + List stringList = Files.readAllLines(filePath, charset); + String[] stringArray = stringList.toArray(new String[] {}); + msoLogger.error(MessageEnum.GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.UnknownError, "test error msg"); + + Assert.assertTrue(stringArray[0] + .contains("|reqId|servId|main||testRecordMetricEvent||VNF|createVNF|COMPLETE|0|Successful|")); + // count the occurance of symbol "|" + Assert.assertTrue((stringArray[0].length() - stringArray[0].replace("|", "").length()) == 28); + Assert.assertTrue(stringArray[1] + .contains("|reqId|servId|main||testRecordMetricEvent|testUser|SDNC|removeSDNC|ERROR|501|Exception|") + && stringArray[1].contains("|127.0.0.1||||testVNF|||||")); + Assert.assertTrue((stringArray[1].length() - stringArray[1].replace("|", "").length()) == 28); + } + + /** + * This method implements a test of testRecordAuditEvent method. + */ + + // User reflection to invoke to avoid change the publicity of the method + private static String invokePrepareMsg(String arg1, String arg2, String arg3) { + Method method; + try { + method = MsoLogger.class.getDeclaredMethod("prepareMsg", String.class, String.class, String.class); + method.setAccessible(true); + return (String) method.invoke(msoLogger, arg1, arg2, arg3); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + // User reflection to invoke to avoid change the publicity of the method + private static Object invokePriveMethod(String methodName, String arg) { + Method method; + try { + method = MsoLogger.class.getDeclaredMethod(methodName, String.class); + method.setAccessible(true); + return method.invoke(msoLogger, arg); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } +} diff --git a/common/src/test/java/org/onap/so/client/RestClientTest.java b/common/src/test/java/org/onap/so/client/RestClientTest.java new file mode 100644 index 0000000000..1443f04f3a --- /dev/null +++ b/common/src/test/java/org/onap/so/client/RestClientTest.java @@ -0,0 +1,87 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.net.MalformedURLException; +import java.net.SocketTimeoutException; + +import javax.ws.rs.NotFoundException; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriBuilderException; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.utils.TargetEntity; + +@RunWith(MockitoJUnitRunner.class) +public class RestClientTest { + + + @Mock + private RestProperties props; + + + @Test + public void retries() throws Exception { + RestClient spy = buildSpy(); + RestRequest mockCallable = mock(RestRequest.class); + when(mockCallable.call()).thenThrow(new WebApplicationException(new SocketTimeoutException())); + doReturn(mockCallable).when(spy).buildRequest(any(String.class), any(Object.class)); + try { + spy.get(); + } catch (Exception e) { + //we expect an exception, ignore it + } + verify(mockCallable, times(3)).call(); + + } + + @Test + public void exceptionDoNotRetry() throws Exception { + RestClient spy = buildSpy(); + RestRequest mockCallable = mock(RestRequest.class); + when(mockCallable.call()).thenThrow(new WebApplicationException(new NotFoundException())); + doReturn(mockCallable).when(spy).buildRequest(any(String.class), any(Object.class)); + try { + spy.get(); + } catch (Exception e) { + //we expect an exception, ignore it + } + verify(mockCallable, times(1)).call(); + + } + private RestClient buildSpy() throws MalformedURLException, IllegalArgumentException, UriBuilderException { + RestClient client = new HttpClient(UriBuilder.fromUri("http://localhost/test").build().toURL(), "application/json", TargetEntity.BPMN); + + return spy(client); + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/AAIClientResponseExceptionMapperTest.java b/common/src/test/java/org/onap/so/client/aai/AAIClientResponseExceptionMapperTest.java new file mode 100644 index 0000000000..981a4ddacc --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/AAIClientResponseExceptionMapperTest.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.onap.so.client.aai.entities.AAIError; +import org.onap.so.client.aai.entities.RequestError; +import org.onap.so.client.aai.entities.ServiceException; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class AAIClientResponseExceptionMapperTest { + + AAIClientResponseExceptionMapper mapper; + String errorMsg; + + @Before + public void before() { + mapper = new AAIClientResponseExceptionMapper(); + errorMsg = "Error calling A&AI. Request-Id=" + mapper.getRequestId() + " "; + } + + @Test + public void testExtractMessageWithEntity() throws JsonProcessingException { + ServiceException svcException = new ServiceException(); + svcException.setText("test %1 message - %2"); + svcException.setVariables(Arrays.asList("error", "service exception %1 test")); + + RequestError requestError = new RequestError(); + requestError.setServiceException(svcException); + + AAIError error = new AAIError(); + error.setRequestError(requestError); + + ObjectMapper objMapper = new ObjectMapper(); + String strRequestError = objMapper.writeValueAsString(error); + + assertEquals(errorMsg + "test error message - service exception error test", mapper.extractMessage(strRequestError).get()); + } + + @Test + public void testExtractMessageWithoutEntity() { + assertEquals(errorMsg, mapper.extractMessage("").get()); + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/AAIConfigurationClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIConfigurationClientTest.java new file mode 100644 index 0000000000..40410019f0 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/AAIConfigurationClientTest.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.Optional; +import java.util.UUID; + +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.client.aai.entities.Configuration; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.RequestDetails; + +import com.github.tomakehurst.wiremock.junit.WireMockRule; +@RunWith(MockitoJUnitRunner.class) +public class AAIConfigurationClientTest { + + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8443)); + + @Mock + AAIResourcesClient aaiClient; + + @InjectMocks + AAIConfigurationClient aaiConfigurationClient = new AAIConfigurationClient(); + + @Test + public void verifyCreate() { + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelInvariantId("testInvariantID"); + modelInfo.setModelVersionId("testVersionID"); + modelInfo.setModelCustomizationId("testCustomizationID"); + + RequestDetails requestDetails = new RequestDetails(); + requestDetails.setModelInfo(modelInfo); + + String configurationId = UUID.randomUUID().toString(); + String configurationType = "test"; + String configurationSubType = "test"; + + // Test Create Configuration + doNothing().when(aaiClient).create(isA(AAIResourceUri.class), isA(Object.class)); + aaiConfigurationClient.createConfiguration(requestDetails, configurationId, configurationType, configurationSubType); + verify(aaiClient, times(1)).create(isA(AAIResourceUri.class), isA(Object.class)); + } + + @Test + public void verifyConfigurePayload() { + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelInvariantId("testInvariantID"); + modelInfo.setModelVersionId("testVersionID"); + modelInfo.setModelCustomizationId("testCustomizationID"); + + RequestDetails requestDetails = new RequestDetails(); + requestDetails.setModelInfo(modelInfo); + + String configurationId = UUID.randomUUID().toString(); + String configurationType = "test"; + String configurationSubType = "test"; + AAIResourceUri uri = aaiConfigurationClient.getConfigurationURI(configurationId); + + Configuration payload = aaiConfigurationClient.configurePayload(requestDetails, configurationId, configurationType, configurationSubType); + + assertEquals(configurationId, payload.getConfigurationId()); + assertEquals(configurationType, payload.getConfigurationType()); + assertEquals(configurationSubType, payload.getConfigurationSubType()); + assertEquals(uri.build().getPath(), payload.getConfigurationSelflink()); + assertEquals("PreCreated", payload.getOrchestrationStatus()); + assertEquals("", payload.getOperationalStatus()); + assertEquals(modelInfo.getModelVersionId(), payload.getModelVersionId()); + assertEquals(modelInfo.getModelInvariantId(), payload.getModelInvariantId()); + assertEquals(modelInfo.getModelCustomizationId(), payload.getModelCustomizationId()); + } + + @Test + public void testDeleteConfiguration() { + String uuid = UUID.randomUUID().toString(); + doNothing().when(aaiClient).delete(isA(AAIResourceUri.class)); + aaiConfigurationClient.deleteConfiguration(uuid); + verify(aaiClient, times(1)).delete(aaiConfigurationClient.getConfigurationURI(uuid)); + } + + @Test + public void testUpdateOrchestrationStatus() { + String uuid = UUID.randomUUID().toString(); + doNothing().when(aaiClient).update(isA(AAIResourceUri.class), isA(Object.class)); + aaiConfigurationClient.updateOrchestrationStatus(uuid, "testPayload"); + verify(aaiClient, times(1)).update(aaiConfigurationClient.getConfigurationURI(uuid), "testPayload"); + } + + @SuppressWarnings("unchecked") + @Test + public void testGetConfiguration() { + String uuid = UUID.randomUUID().toString(); + Optional expectedConfiguration = Optional.of(new Configuration()); + expectedConfiguration.get().setConfigurationId(uuid); + + doReturn(expectedConfiguration).when(aaiClient).get(isA(Class.class), isA(AAIResourceUri.class)); + Configuration actualConfiguration = aaiConfigurationClient.getConfiguration(uuid); + verify(aaiClient, times(1)).get(Configuration.class, aaiConfigurationClient.getConfigurationURI(uuid)); + assertEquals(expectedConfiguration.get(), actualConfiguration); + } + + @Test + public void testConfigurationExists() { + String uuid = UUID.randomUUID().toString(); + AAIResourceUri uri = aaiConfigurationClient.getConfigurationURI(uuid); + boolean expectedResult; + boolean actualResult; + + expectedResult = true; + doReturn(expectedResult).when(aaiClient).exists(isA(AAIResourceUri.class)); + actualResult = aaiConfigurationClient.configurationExists(uuid); + assertEquals(expectedResult, actualResult); + + expectedResult = false; + doReturn(expectedResult).when(aaiClient).exists(isA(AAIResourceUri.class)); + actualResult = aaiConfigurationClient.configurationExists(uuid); + assertEquals(expectedResult, actualResult); + + verify(aaiClient, times(2)).exists(uri); + } + + @Test + public void testGetConfigurationURI() { + String uuid = UUID.randomUUID().toString(); + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, uuid); + assertEquals(uri, aaiConfigurationClient.getConfigurationURI(uuid)); + } + + @Test + public void verifyNotExists() { + AAIUri path = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, "test2"); + wireMockRule.stubFor(get( + urlMatching("/aai/v[0-9]+" + path.build() + ".*")) + .willReturn( + aResponse() + .withHeader("Content-Type", "text/plain") + .withBody("hello") + .withStatus(404))); + boolean result = aaiConfigurationClient.configurationExists("test2"); + assertEquals("path not found", false, result); + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/AAIErrorFormatterTest.java b/common/src/test/java/org/onap/so/client/aai/AAIErrorFormatterTest.java new file mode 100644 index 0000000000..bea927afa5 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/AAIErrorFormatterTest.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.so.client.aai.entities.AAIError; +import org.onap.so.client.aai.entities.RequestError; +import org.onap.so.client.aai.entities.ServiceException; + +public class AAIErrorFormatterTest { + + @Mock private AAIError errorObj; + + @Before + public void init() { + MockitoAnnotations.initMocks(this); + } + @Test + public void testFillInTemplateWithReplace() { + String error = "Error %1 on %2"; + List list = Arrays.asList("PUT", "hello %1"); + AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj); + String result = formatter.fillInTemplate(error, list); + assertEquals("equal", "Error PUT on hello PUT", result); + + } + + @Test + public void testFillInTemplateWithoutReplace() { + String error = "Error"; + List list = new ArrayList<>(); + AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj); + String result = formatter.fillInTemplate(error, list); + assertEquals("equal", "Error", result); + } + + @Test + public void testGetMessage() { + ServiceException svcException = new ServiceException(); + svcException.setText("test %1 message - %2"); + svcException.setVariables(Arrays.asList("error", "service exception %1 test")); + + RequestError requestError = new RequestError(); + requestError.setServiceException(svcException); + + doReturn(requestError).when(errorObj).getRequestError(); + + AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj); + String result = formatter.getMessage(); + assertEquals("equal", "test error message - service exception error test", result); + } + + @Test + public void testGetMessageNoParsable() { + errorObj.setRequestError(null); + AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj); + String result = formatter.getMessage(); + assertEquals("equal", "no parsable error message found", result); + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java b/common/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java new file mode 100644 index 0000000000..ce90ccdc0e --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.so.client.aai.entities.uri.AAIUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; + +public class AAIObjectTypeTest { + + @Test + public void verifyDefaultCase() { + assertEquals("default removed for tenant", "tenant", AAIObjectType.DEFAULT_TENANT.typeName()); + assertEquals("default removed for cloud-region", "cloud-region", AAIObjectType.DEFAULT_CLOUD_REGION.typeName()); + } + + @Test + public void verifyRegularCase() { + assertEquals("default removed for tenant", "allotted-resource", AAIObjectType.ALLOTTED_RESOURCE.typeName()); + } + + @Test + public void instanceGroupObjectTypeTest() { + final String id = "test1"; + AAIUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, id); + assertEquals("/network/instance-groups/instance-group/test1", aaiUri.build().toString()); + } + + @Test + public void collectionObjectTypeTest() { + final String id = "test1"; + AAIUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.COLLECTION, id); + assertEquals("/network/collections/collection/test1", aaiUri.build().toString()); + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/AAIPServerTest.java b/common/src/test/java/org/onap/so/client/aai/AAIPServerTest.java new file mode 100644 index 0000000000..1e2e7471f1 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/AAIPServerTest.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.security.NoSuchAlgorithmException; +import java.util.List; +import java.util.UUID; + +import org.junit.Ignore; +import org.junit.Test; +import org.onap.aai.domain.yang.Pserver; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +public class AAIPServerTest { + + @Test + public void pserverTest() throws JsonParseException, JsonMappingException, IOException, NoSuchAlgorithmException { + AAIRestClientImpl client = new AAIRestClientImpl(); + String json = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/aai/pserver.json"))); + List list = client.getListOfPservers(json); + + assertEquals("", list.get(0).getHostname(), "test"); + } + + @Test + @Ignore // IGNORED FOR 1710 MERGE TO ONAP + public void pserverActualTest() throws JsonParseException, JsonMappingException, IOException, NoSuchAlgorithmException { + AAIRestClientImpl client = new AAIRestClientImpl(); + List list = client.getPhysicalServerByVnfId("d946afed-8ebe-4c5d-9665-54fcc043b8e7", UUID.randomUUID().toString()); + assertEquals("", list.size(), 0); + } + +} diff --git a/common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java new file mode 100644 index 0000000000..6e9c38517d --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.Arrays; +import java.util.List; + +import javax.ws.rs.core.Response; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.client.RestClient; +import org.onap.so.client.aai.entities.CustomQuery; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; +import org.onap.so.client.graphinventory.Format; + + +@RunWith(MockitoJUnitRunner.class) +public class AAIQueryClientTest { + + @Mock + Response response; + + @Mock + RestClient restClient; + + @Spy + AAIQueryClient aaiQueryClient = new AAIQueryClient(); + + @Test + public void testQuery() { + List uris = Arrays.asList(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY)); + + Format format = Format.SIMPLE; + CustomQuery query = new CustomQuery(uris); + + doReturn(restClient).when(aaiQueryClient).createClient(isA(AAIUri.class)); + aaiQueryClient.query(format, query); + verify(aaiQueryClient, times(1)).createClient(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY).queryParam("format", format.toString())); + verify(restClient, times(1)).put(query, String.class); + } + + @Test + public void testCreateClient() { + String depth = "testDepth"; + AAISubgraphType subgraph = AAISubgraphType.STAR; + + aaiQueryClient.depth(depth); + aaiQueryClient.nodesOnly(); + aaiQueryClient.subgraph(subgraph); + + AAIUri aaiUri = spy(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY)); + doReturn(aaiUri).when(aaiUri).clone(); + aaiQueryClient.setupQueryParams(aaiUri); + + verify(aaiUri, times(1)).queryParam("depth", depth); + verify(aaiUri, times(1)).queryParam("nodesOnly", ""); + verify(aaiUri, times(1)).queryParam("subgraph", subgraph.toString()); + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java new file mode 100644 index 0000000000..63f8f652ce --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java @@ -0,0 +1,191 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.delete; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.put; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; +import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl; + +import com.github.tomakehurst.wiremock.admin.NotFoundException; +import com.github.tomakehurst.wiremock.junit.WireMockRule; +public class AAIResourcesClientTest { + + + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8443)); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void verifyNotExists() { + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test"); + wireMockRule.stubFor(get( + urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())) + .willReturn( + aResponse() + .withHeader("Content-Type", "text/plain") + .withBody("hello") + .withStatus(404))); + AAIResourcesClient client= createClient(); + boolean result = client.exists(path); + assertEquals("path not found", false, result); + } + + @Test + public void verifyDelete() { + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2"); + wireMockRule.stubFor(get( + urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())) + .willReturn( + aResponse() + .withHeader("Content-Type", "application/json") + .withBodyFile("aai/resources/mockObject.json") + .withStatus(200))); + wireMockRule.stubFor(delete( + urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())) + .withQueryParam("resource-version", equalTo("1234")) + .willReturn( + aResponse() + .withStatus(204))); + AAIResourcesClient client= createClient(); + client.delete(path); + } + + @Test + public void verifyBasicAuth() { + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3"); + wireMockRule.stubFor(get( + urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString())) + .withHeader("Authorization", equalTo("Basic TVNPOk1TTw==")) + .willReturn( + aResponse() + .withHeader("Content-Type", "application/json") + .withBodyFile("aai/resources/mockObject.json") + .withStatus(200))); + AAIResourcesClient client= createClient(); + client.get(path); + } + + @Test + public void verifyConnect() { + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2"); + AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3"); + wireMockRule.stubFor(put( + urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build() + "/relationship-list/relationship")) + .willReturn( + aResponse() + .withHeader("Content-Type", "application/json") + .withStatus(200))); + + AAIResourceUri pathClone = path.clone(); + AAIResourcesClient client= createClient(); + client.connect(path, path2); + assertEquals("uri not modified", pathClone.build().toString(), path.build().toString()); + } + + @Test + public void verifyDisconnect() { + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2"); + AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3"); + + wireMockRule.stubFor(post( + urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build() + "/relationship-list/relationship")) + .willReturn( + aResponse() + .withStatus(204))); + + AAIResourceUri pathClone = path.clone(); + AAIResourcesClient client= createClient(); + client.disconnect(path, path2); + assertEquals("uri not modified", pathClone.build().toString(), path.build().toString()); + } + + @Test + public void verifyPatch() { + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2"); + + wireMockRule.stubFor(post( + urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())) + .willReturn( + aResponse() + .withStatus(200))); + + AAIResourcesClient client= createClient(); + + client.update(path, "{}"); + } + + @Test + public void verifyNotExistsGet() { + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test"); + wireMockRule.stubFor(get( + urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())) + .willReturn( + aResponse() + .withHeader("Content-Type", "text/plain") + .withBody("hello") + .withStatus(404))); + AAIResourcesClient client= createClient(); + AAIResultWrapper result = client.get(path); + assertEquals("is empty", true, result.isEmpty()); + } + + @Test + public void verifyNotExistsGetException() { + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test"); + wireMockRule.stubFor(get( + urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())) + .willReturn( + aResponse() + .withHeader("Content-Type", "text/plain") + .withBody("hello") + .withStatus(404))); + AAIResourcesClient client= createClient(); + thrown.expect(NotFoundException.class); + thrown.expectMessage(containsString(path.build() + " not found in A&AI")); + AAIResultWrapper result = client.get(path, NotFoundException.class); + } + + private AAIResourcesClient createClient() { + AAIResourcesClient client = spy(new AAIResourcesClient()); + doReturn(new DefaultAAIPropertiesImpl()).when(client).getRestProperties(); + return client; + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java new file mode 100644 index 0000000000..f2e371c999 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; + +import javax.ws.rs.core.Response; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.so.client.graphinventory.exceptions.GraphInventoryPatchDepthExceededException; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(MockitoJUnitRunner.class) +public class AAIRestClientTest { + + @Mock + private AAIProperties props; + + private ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper(); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void convertObjectToPatchFormatTest() throws URISyntaxException, JsonParseException, JsonMappingException, IOException { + AAIRestClient client = new AAIRestClient(props, new URI("")); + GenericVnf vnf = new GenericVnf(); + vnf.setIpv4Loopback0Address(""); + String result = client.convertObjectToPatchFormat(vnf); + GenericVnf resultObj = mapper.readValue(result.toString(), GenericVnf.class); + assertTrue("expect object to become a String to prevent double marshalling", result instanceof String); + assertNull("expect null because of custom mapper", resultObj.getIpv4Loopback0Address()); + + } + + @Test + public void convertStringToPatchFormatTest() throws URISyntaxException, JsonParseException, JsonMappingException, IOException { + AAIRestClient client = new AAIRestClient(props, new URI("")); + String payload = "{\"ipv4-loopback0-address\":\"\"}"; + String result = client.convertObjectToPatchFormat(payload); + + assertEquals("expect no change", payload, result); + } + + @Test + public void convertMapToPatchFormatTest() throws URISyntaxException, JsonParseException, JsonMappingException, IOException { + AAIRestClient client = new AAIRestClient(props, new URI("")); + HashMap map = new HashMap<>(); + map.put("ipv4-loopback0-address", ""); + String result = client.convertObjectToPatchFormat(map); + + assertEquals("expect string", "{\"ipv4-loopback0-address\":\"\"}", result); + } + + @Test + public void failPatchOnComplexObject() throws URISyntaxException { + AAIRestClient client = new AAIRestClient(props, new URI("")); + this.thrown.expect(GraphInventoryPatchDepthExceededException.class); + this.thrown.expectMessage(containsString("Object exceeds allowed depth for update action")); + client.patch("{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"relationship-list\" : [{\"key\" : \"value\"}], \"nested\" : { \"key\" : \"value\" }}"); + + } + + @Test + public void hasComplexObjectTest() throws URISyntaxException { + AAIRestClient client = new AAIRestClient(props, new URI("")); + String hasNesting = "{ \"hello\" : \"world\", \"nested\" : { \"key\" : \"value\" } }"; + String noNesting = "{ \"hello\" : \"world\" }"; + String arrayCase = "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"nestedComplex\" : [{\"key\" : \"value\"}]}"; + String empty = "{}"; + String arrayCaseSimpleOnly = "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"]}"; + String relationshipListCaseNesting = "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"relationship-list\" : [{\"key\" : \"value\"}], \"nested\" : { \"key\" : \"value\" }}"; + String relationshipListCase = "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"relationship-list\" : [{\"key\" : \"value\"}]}"; + String nothing = ""; + + assertTrue("expect has nesting", client.hasComplexObject(hasNesting)); + assertFalse("expect no nesting", client.hasComplexObject(noNesting)); + assertTrue("expect has nesting", client.hasComplexObject(arrayCase)); + assertFalse("expect no nesting", client.hasComplexObject(empty)); + assertFalse("expect no nesting", client.hasComplexObject(arrayCaseSimpleOnly)); + assertFalse("expect no nesting", client.hasComplexObject(relationshipListCase)); + assertTrue("expect has nesting", client.hasComplexObject(relationshipListCaseNesting)); + assertFalse("expect no nesting", client.hasComplexObject(nothing)); + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java new file mode 100644 index 0000000000..f6ee826a78 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java @@ -0,0 +1,148 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; + +import org.onap.aai.domain.yang.Relationship; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; +import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; + +public class AAITransactionalClientTest { + + private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/bulkprocess/"; + AAIResourceUri uriA = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1"); + AAIResourceUri uriB = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test2"); + AAIResourceUri uriC = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3"); + AAIResourceUri uriD = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test4"); + AAIResourceUri uriE = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test5"); + AAIResourceUri uriF = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test6"); + + ObjectMapper mapper; + + @Before + public void before() throws JsonParseException, JsonMappingException, IOException { + mapper = new AAICommonObjectMapperProvider().getMapper(); + mapper.enable(SerializationFeature.INDENT_OUTPUT); + } + + @Test + public void testCreate() throws IOException { + final Relationship body = new Relationship(); + body.setRelatedLink(uriB.build().toString()); + + AAITransactionalClient transactions = createClient().beginTransaction() + .create(uriA.clone().relationshipAPI(), body); + + String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions()); + Map actual = mapper.readValue(serializedTransactions, new TypeReference>(){}); + Map expected = mapper.readValue(getJson("test-request-small.json"), new TypeReference>(){}); + + assertEquals(actual, expected); + } + + @Test + public void testConnect() throws IOException { + List uris = new ArrayList(); + uris.add(uriB); + + AAIResourceUri uriAClone = uriA.clone(); + AAITransactionalClient transactions = createClient() + .beginTransaction().connect(uriA, uris).connect(uriC, uriD) + .beginNewTransaction().connect(uriE, uriF); + + String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions()); + Map actual = mapper.readValue(serializedTransactions, new TypeReference>(){}); + Map expected = mapper.readValue(getJson("test-request.json"), new TypeReference>(){}); + + assertEquals(actual, expected); + assertEquals("uri not manipulated", uriAClone.build().toString(), uriA.build().toString()); + } + + @Test + public void testDisconnect() throws IOException { + List uris = new ArrayList(); + uris.add(uriB); + + AAITransactionalClient transactions = createClient().beginTransaction() + .disconnect(uriA, uris); + + String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions()); + Map actual = mapper.readValue(serializedTransactions, new TypeReference>(){}); + Map expected = mapper.readValue(getJson("test-request-small.json").replace("put", "delete"), new TypeReference>(){}); + + assertEquals(actual, expected); + } + + @Test + public void testUpdate() throws IOException { + final Relationship body = new Relationship(); + body.setRelatedLink(uriB.build().toString()); + + AAIResourceUri uriAClone = uriA.clone().relationshipAPI(); + AAITransactionalClient transactions = createClient().beginTransaction().update(uriAClone, body); + + String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions()); + Map actual = mapper.readValue(serializedTransactions, new TypeReference>(){}); + Map expected = mapper.readValue(getJson("test-request-small.json").replace("put", "patch"), new TypeReference>(){}); + + assertEquals(actual, expected); + } + + @Test + public void verifyResponse() throws IOException { + AAITransactionalClient transactions = createClient() + .beginTransaction(); + + assertEquals("success status", Optional.empty(), transactions.locateErrorMessages(getJson("response-success.json"))); + assertEquals(transactions.locateErrorMessages(getJson("response-failure.json")).get(), "another error message\nmy great error"); + } + + private String getJson(String filename) throws IOException { + return new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + filename))); + } + + private AAIResourcesClient createClient() { + AAIResourcesClient client = spy(new AAIResourcesClient()); + doReturn(new DefaultAAIPropertiesImpl()).when(client).getRestProperties(); + return client; + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/AAIURITest.java b/common/src/test/java/org/onap/so/client/aai/AAIURITest.java new file mode 100644 index 0000000000..cb426c5392 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/AAIURITest.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai; + +import static org.junit.Assert.assertEquals; + +import javax.ws.rs.core.UriBuilder; + +import org.junit.Test; +import org.onap.so.client.aai.entities.uri.AAIUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; + +public class AAIURITest { + + + + + @Test + public void verifyTemplateReplacement() { + final String id = "test1"; + AAIUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, id); + String manualReplace = AAIObjectType.CONFIGURATION.toString().replaceAll("\\{configuration-id\\}", id); + assertEquals("uri template replaced", aaiUri.build(), UriBuilder.fromPath(manualReplace).build()); + + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/AAIUpdatorImplTest.java b/common/src/test/java/org/onap/so/client/aai/AAIUpdatorImplTest.java new file mode 100644 index 0000000000..7ba92a1f06 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/AAIUpdatorImplTest.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai; + +import org.junit.Test; + +public class AAIUpdatorImplTest { + + AAIUpdatorImpl test = new AAIUpdatorImpl(); + + protected AAIRestClientI client; + + @Test + public void getClientTest() throws Exception { + test.getClient(); + } + + @Test + public void setClientTest() throws Exception { + test.setClient(client); + } + + + @Test(expected = NullPointerException.class) + public void updateVnfToLockedTest() throws Exception { + test.updateVnfToLocked("vnfId","uuId"); + } + + + @Test(expected = NullPointerException.class) + public void updateVnfToUnLockedTest() throws Exception { + test.updateVnfToUnLocked("vnfId","uuId"); + } + +} diff --git a/common/src/test/java/org/onap/so/client/aai/AAIUpdatorTest.java b/common/src/test/java/org/onap/so/client/aai/AAIUpdatorTest.java new file mode 100644 index 0000000000..fddd1e63ba --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/AAIUpdatorTest.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai; + +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class AAIUpdatorTest { + + @Mock + protected AAIRestClientI client; + String vnfName = "testVnf"; + String uuid = "UUID"; + AAIUpdatorImpl updator; + + @Before + public void init(){ + updator = new AAIUpdatorImpl(); + updator.setClient(client); + } + + @Test + public void testUpdateVnfToLocked() throws Exception{ + doNothing().when(client).updateMaintenceFlagVnfId(isA(String.class), isA(Boolean.class), isA(String.class)); + updator.updateVnfToLocked(vnfName, uuid); + verify(client, times(1)).updateMaintenceFlagVnfId(vnfName, true, uuid); + } + + @Test + public void testUpdateVnfToUnLocked() throws Exception { + doNothing().when(client).updateMaintenceFlagVnfId(isA(String.class), isA(Boolean.class), isA(String.class)); + updator.updateVnfToUnLocked(vnfName, uuid); + verify(client, times(1)).updateMaintenceFlagVnfId(vnfName, false, uuid); + } +} \ No newline at end of file diff --git a/common/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java b/common/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java new file mode 100644 index 0000000000..04c8b15b51 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.Pserver; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; + +@RunWith(MockitoJUnitRunner.class) +public class AAIValidatorTest { + + @Mock + protected AAIRestClientI client; + String vnfName = "testVnf"; + String uuid = "UUID"; + AAIValidatorImpl validator; + + @Before + public void init(){ + validator = new AAIValidatorImpl(); + validator.setClient(client); + } + + public List getPservers(boolean locked){ + Pserver pserver = new Pserver(); + pserver.setInMaint(locked); + List pservers = new ArrayList(); + pservers.add(pserver); + return pservers; + } + + public GenericVnf createGenericVnfs(boolean locked){ + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setInMaint(locked); + return genericVnf; + } + + @Test + public void test_IsPhysicalServerLocked_True() throws IOException{ + when(client.getPhysicalServerByVnfId(vnfName,uuid)).thenReturn(getPservers(true)); + boolean locked = validator.isPhysicalServerLocked(vnfName, uuid); + assertEquals(true, locked); + } + + @Test + public void test_IsPhysicalServerLocked_False() throws JsonParseException, JsonMappingException, UnsupportedEncodingException, IOException { + when(client.getPhysicalServerByVnfId(vnfName,uuid)).thenReturn(getPservers(false)); + boolean locked = validator.isPhysicalServerLocked(vnfName, uuid); + assertEquals(false, locked); + } + + @Test + public void test_IsVNFLocked_False() throws Exception{ + when(client.getVnfByName(vnfName,uuid)).thenReturn(createGenericVnfs(false)); + boolean locked = validator.isVNFLocked(vnfName, uuid); + assertEquals(false, locked); + } + + @Test + public void test_IsVNFLocked_True() throws Exception{ + when(client.getVnfByName(vnfName,uuid)).thenReturn(createGenericVnfs(true)); + boolean locked = validator.isVNFLocked(vnfName, uuid); + assertEquals(true,locked ); + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java b/common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java new file mode 100644 index 0000000000..ff940a0dea --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai.entities; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.so.client.aai.AAICommonObjectMapperProvider; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(MockitoJUnitRunner.class) +public class AAIResultWrapperTest { + String json; + + AAIResultWrapper aaiResultWrapper; + AAIResultWrapper aaiResultWrapperEmpty; + + @Before + public void init() throws IOException { + final String RESOURCE_PATH = "src/test/resources/__files/aai/resources/"; + json = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "e2e-complex.json"))); + + aaiResultWrapper = new AAIResultWrapper(json); + aaiResultWrapperEmpty = new AAIResultWrapper("{}"); + } + + @Test + public void testGetRelationshipsEmpty() { + Optional relationships = aaiResultWrapperEmpty.getRelationships(); + assertEquals("Compare relationships", Optional.empty(), relationships); + } + + @Test + public void testAsMap() throws JsonParseException, JsonMappingException, IOException { + ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper(); + Map expected = mapper.readValue(json, new TypeReference>(){}); + + Map actual = aaiResultWrapper.asMap(); + assertEquals(expected, actual); + } + + @Test + public void testAsMapEmpty() { + Map actual = aaiResultWrapperEmpty.asMap(); + assertEquals(new HashMap<>(), actual); + } + + @Test + public void nullCases() { + + AAIResultWrapper wrapper = new AAIResultWrapper(null); + + assertEquals(Optional.empty(), wrapper.getRelationships()); + assertEquals("{}", wrapper.getJson()); + assertEquals(Optional.empty(), wrapper.asBean(GenericVnf.class)); + assertEquals(true, wrapper.asMap().isEmpty()); + assertEquals("{}", wrapper.toString()); + + + + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java b/common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java new file mode 100644 index 0000000000..1ce6e4377c --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai.entities; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; + +public class RelationshipsTest { + + private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/resources/"; + + @Test + public void run() throws IOException { + final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "e2e-complex.json"))); + + AAIResultWrapper wrapper = new AAIResultWrapper(content); + Relationships relationships = wrapper.getRelationships().get(); + + List test = relationships.getRelatedAAIUris(AAIObjectType.VCE); + + System.out.println(test.get(0).build()); + List uris = Arrays.asList( + AAIUriFactory.createResourceUri(AAIObjectType.VCE, "a9fec18e-1ea3-40e4-a6c0-a89b3de07053"), + AAIUriFactory.createResourceUri(AAIObjectType.VCE, "8ae1e5f8-61f1-4c71-913a-b40cc4593cb9"), + AAIUriFactory.createResourceUri(AAIObjectType.VCE, "a2935fa9-b743-49f4-9813-a127f13c4e93"), + AAIUriFactory.createResourceUri(AAIObjectType.VCE, "c7fe7698-8063-4e26-8bd3-ca3edde0b0d4")); + + + assertTrue(uris.containsAll(test) && test.containsAll(uris)); + + } + +} diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java new file mode 100644 index 0000000000..5a69a42f35 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai.entities.uri; + +import static org.junit.Assert.assertEquals; + +import javax.ws.rs.core.UriBuilder; + +import org.junit.Test; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.graphinventory.entities.uri.SimpleUri; + +public class AAISimpleUriFromUriTest { + + + + @Test + public void removeHost() { + + AAIUri uri = new AAISimpleUri(AAIObjectType.UNKNOWN, UriBuilder.fromUri("https://localhost:8443/aai/v9/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053").build()); + + assertEquals("root and version removed", "/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053", uri.build().toString()); + + } + @Test + public void noChange() { + + AAIUri uri = new AAISimpleUri(AAIObjectType.UNKNOWN, UriBuilder.fromUri("/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053").build()); + + assertEquals("no change", "/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053", uri.build().toString()); + + } + + @Test + public void encodingPreserved() { + + AAIUri uri = new AAISimpleUri(AAIObjectType.UNKNOWN, UriBuilder.fromUri("/network/vces/vce/a9f%20%20ec18e-1ea3-40e4-a6c0-a89b3de07053").build()); + + assertEquals("encoding preserved", "/network/vces/vce/a9f%20%20ec18e-1ea3-40e4-a6c0-a89b3de07053", uri.build().toString()); + + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java new file mode 100644 index 0000000000..1b6cc7bf66 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai.entities.uri; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.collection.IsIterableContainingInOrder.contains; +import static org.hamcrest.collection.IsEmptyCollection.empty; +import static org.junit.Assert.assertEquals; + +import java.util.Map; + +import org.junit.Test; +import org.onap.so.client.aai.AAIObjectPlurals; +import org.onap.so.client.aai.AAIObjectType; + +public class AAISimpleUriTest { + + + + @Test + public void relatedToTestPlural() { + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1"); + uri.relatedTo(AAIObjectPlurals.PSERVER); + String uriOutput = uri.build().toString(); + assertEquals(true, uriOutput.contains("related-to")); + } + + @Test + public void relatedToTestSingular() { + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1"); + uri.relatedTo(AAIObjectType.PSERVER, "test2"); + String uriOutput = uri.build().toString(); + assertEquals(true, uriOutput.contains("related-to")); + } + + @Test + public void cloneTestSingular() { + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1"); + AAIResourceUri cloned = uri.clone(); + Map keys = cloned.getURIKeys(); + assertThat(keys.values(), contains("test1")); + } + + @Test + public void cloneTestPlural() { + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF); + AAIResourceUri cloned = uri.clone(); + Map keys = cloned.getURIKeys(); + assertThat(keys.values(), empty()); + } + + @Test + public void getKeysTest() { + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, "cloud1", "cloud2", "tenant1", "vserver1"); + Map keys = uri.getURIKeys(); + System.out.println(keys); + System.out.println(uri.build()); + assertEquals("vserver1", keys.get("vserver-id")); + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java new file mode 100644 index 0000000000..0ddf5c707b --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai.entities.uri; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.so.client.aai.AAIObjectPlurals; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.graphinventory.entities.uri.SimpleUri; + +public class AAIUriFactoryTest { + + @Test + public void testCreateResourceUri() { + + AAIUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)"); + + String expected = "/network/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29"; + assertEquals(expected, uri.build().toString()); + } + + @Test + public void testCreateNodesUri() { + + AAIUri uri = AAIUriFactory.createNodesUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)"); + + String expected = "/nodes/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29"; + assertEquals(expected, uri.build().toString()); + } + + @Test + public void testCreateResourceFromExistingURI() { + + AAIUri uri = new AAISimpleUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)"); + AAIUri uri2 = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.GENERIC_VNF, uri.build()); + + String expected = "/network/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29"; + assertEquals(expected, uri2.build().toString()); + } + + @Test + public void testCreateResourceURIForPluralsWithValues() { + + AAIUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, "customerId", "serviceType"); + + String expected = "/business/customers/customer/customerId/service-subscriptions/service-subscription/serviceType/service-instances"; + assertEquals(expected, uri.build().toString()); + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java new file mode 100644 index 0000000000..73720f55c2 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java @@ -0,0 +1,192 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai.entities.uri; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.containing; +import static com.github.tomakehurst.wiremock.client.WireMock.put; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.collection.IsIterableContainingInOrder.contains; +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +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 java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Optional; + +import javax.ws.rs.core.UriBuilder; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.client.aai.AAIQueryClient; +import org.onap.so.client.graphinventory.Format; +import org.onap.so.client.aai.entities.CustomQuery; +import org.onap.so.client.graphinventory.exceptions.GraphInventoryPayloadException; +import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriComputationException; +import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriNotFoundException; + +import com.github.tomakehurst.wiremock.junit.WireMockRule; + +public class ServiceInstanceUriTest { + + private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/resources/"; + + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8443)); + + @Rule + public final ExpectedException exception = ExpectedException.none(); + + @Test + public void found() throws IOException { + final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "service-instance-pathed-query.json"))); + + ServiceInstanceUri instance = new ServiceInstanceUri("key3"); + final Optional result = instance.extractRelatedLink(content); + final String expected = "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3"; + assertEquals("result is equal", expected, result.get()); + + } + + @Test + public void oneKey() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException { + + ServiceInstanceUri instance = new ServiceInstanceUri("key1"); + ServiceInstanceUri spy = spy(instance); + doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3").when(spy).getSerivceInstance(any(Object.class)); + + final URI result = spy.build(); + final URI expected = UriBuilder.fromPath("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3").build(); + assertEquals("result is equal", expected, result); + + } + + @Test + public void oneKeyQueryParams() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException { + + ServiceInstanceUri instance = new ServiceInstanceUri("key1"); + ServiceInstanceUri spy = spy(instance); + doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3").when(spy).getSerivceInstance(any(Object.class)); + + final URI result = spy.resourceVersion("1234").build(); + final URI expected = UriBuilder.fromUri("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3?resource-version=1234").build(); + assertEquals("result is equal", expected, result); + + } + + @Test + public void oneKeyEncoded() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException { + + ServiceInstanceUri instance = new ServiceInstanceUri("key1"); + ServiceInstanceUri spy = spy(instance); + doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%20space").when(spy).getSerivceInstance(any(Object.class)); + + final URI result = spy.build(); + final URI expected = UriBuilder.fromUri("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%20space").build(); + assertEquals("result is equal", expected, result); + + } + + @Test + public void oneKeyGetKeys() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException { + + ServiceInstanceUri instance = new ServiceInstanceUri("key1"); + ServiceInstanceUri spy = spy(instance); + doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%28space").when(spy).getSerivceInstance(any(Object.class)); + + assertThat(spy.getURIKeys().values(), contains("key1", "key2", "key3(space")); + + } + @Test + public void oneKeyClone() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException { + ServiceInstanceUri instance = new ServiceInstanceUri("key1"); + ServiceInstanceUri spy = spy(instance); + String uri = "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3"; + doReturn(uri).when(spy).getSerivceInstance(any(Object.class)); + doReturn(Optional.of(uri)).when(spy).getCachedValue(); + final URI result = spy.resourceVersion("1234").clone().build(); + final URI expected = UriBuilder.fromUri("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3?resource-version=1234").build(); + assertEquals("result is equal", expected, result); + } + + @Test + public void threeKey() throws IOException { + + ServiceInstanceUri instance = new ServiceInstanceUri("key1", "key2", "key3"); + final URI result = instance.build(); + final URI expected = UriBuilder.fromPath("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3").build(); + assertEquals("result is equal", expected, result); + + } + + @Test + public void notfound() throws IOException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException { + final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "empty-query-result.json"))); + + ServiceInstanceUri instance = new ServiceInstanceUri("key3"); + ServiceInstanceUri spy = spy(instance); + AAIQueryClient mockQueryClient = mock(AAIQueryClient.class); + when(mockQueryClient.query(any(Format.class), any(CustomQuery.class))).thenReturn(content); + when(spy.getQueryClient()).thenReturn(mockQueryClient); + exception.expect(GraphInventoryUriComputationException.class); + spy.build(); + + } + + @Test + public void cloneTest() { + ServiceInstanceUri instance = new ServiceInstanceUri("key1", "key2", "key3"); + final URI result = instance.build(); + final URI result2 = instance.clone().queryParam("something", "new").build(); + assertEquals("uris are not equal", false, result.toString().equals(result2.toString())); + + } + + @Test + public void noVertexFound() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException { + ServiceInstanceUri instance = new ServiceInstanceUri("key3"); + ServiceInstanceUri spy = spy(instance); + AAIQueryClient client = mock(AAIQueryClient.class); + when(client.query(any(Format.class), any(CustomQuery.class))).thenReturn("{\"results\":[]}"); + doReturn(client).when(spy).getQueryClient(); + stubFor(put(urlMatching("/aai/v[0-9]+/query.*")) + .withRequestBody(containing("key3")) + .willReturn(aResponse() + .withStatus(400) + .withHeader("Content-Type", "application/json") + .withBodyFile(""))); + exception.expect(GraphInventoryUriComputationException.class); + exception.expectMessage(containsString("NotFoundException")); + spy.build(); + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/objects/AAIOperationalEnvironmentTest.java b/common/src/test/java/org/onap/so/client/aai/objects/AAIOperationalEnvironmentTest.java new file mode 100644 index 0000000000..e2a3cbd6bd --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/objects/AAIOperationalEnvironmentTest.java @@ -0,0 +1,55 @@ +/* +* ============LICENSE_START======================================================= + * ONAP : SO + * ================================================================================ + * Copyright (C) 2018 TechMahindra + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= +*/ +package org.onap.so.client.aai.objects; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class AAIOperationalEnvironmentTest { + + AAIOperationalEnvironment aaiOE =new AAIOperationalEnvironment(); + + @Test + public void test() { + aaiOE.setOperationalEnvironmentId("operationalEnvironmentId"); + aaiOE.setOperationalEnvironmentName("operationalEnvironmentName"); + aaiOE.setOperationalEnvironmentStatus("operationalEnvironmentStatus"); + aaiOE.setOperationalEnvironmentType("operationalEnvironmentType"); + aaiOE.setResourceVersion("resourceVersion"); + aaiOE.setTenantContext("tenantContext"); + aaiOE.setWorkloadContext("workloadContext"); + assertEquals(aaiOE.getOperationalEnvironmentId(),"operationalEnvironmentId"); + assertEquals(aaiOE.getOperationalEnvironmentName(),"operationalEnvironmentName"); + assertEquals(aaiOE.getOperationalEnvironmentStatus(),"operationalEnvironmentStatus"); + assertEquals(aaiOE.getOperationalEnvironmentType(),"operationalEnvironmentType"); + assertEquals(aaiOE.getResourceVersion(),"resourceVersion"); + assertEquals(aaiOE.getTenantContext(),"tenantContext"); + assertEquals(aaiOE.getWorkloadContext(),"workloadContext"); + aaiOE.withOperationalEnvironmentId("operationalEnvironmentId"); + aaiOE.withOperationalEnvironmentName("operationalEnvironmentName"); + aaiOE.withOperationalEnvironmentStatus("operationalEnvironmentStatus"); + aaiOE.withOperationalEnvironmentType("operationalEnvironmentType"); + aaiOE.withResourceVersion("resourceVersion"); + aaiOE.withTenantContext("tenantContext"); + aaiOE.withWorkloadContext("workloadContext"); + } + +} diff --git a/common/src/test/java/org/onap/so/client/aai/objects/AAIServiceInstanceTest.java b/common/src/test/java/org/onap/so/client/aai/objects/AAIServiceInstanceTest.java new file mode 100644 index 0000000000..4b080252b2 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/objects/AAIServiceInstanceTest.java @@ -0,0 +1,53 @@ +/* +* ============LICENSE_START======================================================= + * ONAP : SO + * ================================================================================ + * Copyright (C) 2018 TechMahindra + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= +*/ +package org.onap.so.client.aai.objects; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class AAIServiceInstanceTest { + + @Test + public void test() { + AAIServiceInstance aaiSI= new AAIServiceInstance(); + aaiSI.setEnvironmentContext("environmentContext"); + aaiSI.setModelInvariantUuid("modelInvariantUuid"); + aaiSI.setModelUuid("modelUuid"); + aaiSI.setoStatus("oStatus"); + aaiSI.setServiceInstanceId("serviceInstanceId"); + aaiSI.setServiceInstanceName("serviceInstanceName"); + aaiSI.setServiceRole("serviceRole"); + aaiSI.setServiceType("serviceType"); + aaiSI.setWorkloadContext("workloadContext"); + assertEquals(aaiSI.getEnvironmentContext(), "environmentContext"); + assertEquals(aaiSI.getModelInvariantUuid(), "modelInvariantUuid"); + assertEquals(aaiSI.getModelUuid(), "modelUuid"); + assertEquals(aaiSI.getoStatus(), "oStatus"); + assertEquals(aaiSI.getServiceInstanceId(), "serviceInstanceId"); + assertEquals(aaiSI.getServiceInstanceName(), "serviceInstanceName"); + assertEquals(aaiSI.getServiceRole(), "serviceRole"); + assertEquals(aaiSI.getServiceType(), "serviceType"); + assertEquals(aaiSI.getWorkloadContext(), "workloadContext"); + aaiSI.withServiceInstance("serviceInstanceId"); + assert(aaiSI.getUri()!=null); + } + +} diff --git a/common/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java b/common/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java new file mode 100644 index 0000000000..77e1dfee7d --- /dev/null +++ b/common/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.defaultproperties; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import org.onap.so.client.aai.AAIProperties; +import org.onap.so.client.aai.AAIVersion; + +public class DefaultAAIPropertiesImpl implements AAIProperties { + + + final Map props; + public DefaultAAIPropertiesImpl() { + File initialFile = new File("src/test/resources/aai.properties"); + Map temp; + try (InputStream targetStream = new FileInputStream(initialFile)) { + Properties properties = new Properties(); + properties.load(targetStream); + temp = properties; + } catch (IOException e) { + temp = new HashMap<>(); + } + this.props = temp; + + } + @Override + public URL getEndpoint() throws MalformedURLException { + return new URL(props.get("aai.endpoint").toString()); + } + + @Override + public String getSystemName() { + return "MSO"; + } + @Override + public AAIVersion getDefaultVersion() { + return AAIVersion.LATEST; + } + + @Override + public String getAuth() { + Object value = props.get("aai.auth"); + return value == null ? null : value.toString(); + } + + @Override + public String getKey() { + Object value = props.get("mso.msoKey"); + return value == null ? null : value.toString(); + } +} diff --git a/common/src/test/java/org/onap/so/client/dmaap/DmaapClientTest.java b/common/src/test/java/org/onap/so/client/dmaap/DmaapClientTest.java new file mode 100644 index 0000000000..4b90cfe021 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/dmaap/DmaapClientTest.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.dmaap; + +import static org.junit.Assert.assertEquals; + +import java.io.FileNotFoundException; +import java.io.IOException; + +import org.junit.Test; +import org.onap.so.client.sdno.dmaap.SDNOHealthCheckDmaapConsumer; + +public class DmaapClientTest { + + @Test + public void deobfuscateTest() throws FileNotFoundException, IOException { + String encodedBase64 = "dGVzdHBhc3N3b3Jk"; + String notEncoded = "testpassword"; + DmaapConsumer consumer = new SDNOHealthCheckDmaapConsumer(); + assertEquals("decoded password", notEncoded, consumer.deobfuscatePassword(encodedBase64)); + + } +} diff --git a/common/src/test/java/org/onap/so/client/dmaap/DmaapPublisherTest.java b/common/src/test/java/org/onap/so/client/dmaap/DmaapPublisherTest.java new file mode 100644 index 0000000000..e1afa82e1e --- /dev/null +++ b/common/src/test/java/org/onap/so/client/dmaap/DmaapPublisherTest.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.client.dmaap; + +import org.junit.Test; + +import javax.ws.rs.ProcessingException; +import java.io.IOException; +import java.util.Optional; + +public class DmaapPublisherTest { + + DmaapPublisher dmaapPublisher = new DmaapPublisher(120) { + @Override + public String getUserName() { + return "test"; + } + + @Override + public String getPassword() { + return "test"; + } + + @Override + public String getTopic() { + return "test"; + } + + @Override + public Optional getHost() { + return Optional.of("http://localhost:8080"); + } + }; + + public DmaapPublisherTest() throws IOException { + } + + @Test(expected = ProcessingException.class) + public void sendTest() throws Exception { + dmaapPublisher.send("{'key': 'value'}"); + } + +} \ No newline at end of file diff --git a/common/src/test/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java b/common/src/test/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java new file mode 100644 index 0000000000..be93f47585 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.graphinventory.entities.uri.parsers; + +import static org.junit.Assert.assertEquals; + +import java.util.Map; + +import org.junit.Test; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.graphinventory.entities.uri.parsers.UriParser; +import org.onap.so.client.graphinventory.entities.uri.parsers.UriParserSpringImpl; + +public class UriParserSpringImplTest { + + + + + @Test + public void reverseTemplate() { + final UriParser parser = new UriParserSpringImpl(AAIObjectType.SERVICE_INSTANCE.toString()); + final String uri = "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3"; + + Map result = parser.parse(uri); + + assertEquals("found customer-id", "key1", result.get("global-customer-id")); + assertEquals("found service-type", "key2", result.get("service-type")); + assertEquals("found service-instance-id", "key3", result.get("service-instance-id")); + + } +} diff --git a/common/src/test/java/org/onap/so/client/graphinventory/exceptions/GraphInventoryPayloadExceptionTest.java b/common/src/test/java/org/onap/so/client/graphinventory/exceptions/GraphInventoryPayloadExceptionTest.java new file mode 100644 index 0000000000..6b23cbbe86 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/graphinventory/exceptions/GraphInventoryPayloadExceptionTest.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.graphinventory.exceptions; + +import org.junit.Test; +import org.onap.so.client.graphinventory.exceptions.GraphInventoryPayloadException; + +public class GraphInventoryPayloadExceptionTest { + + Throwable t = new Throwable(); + + @Test + public void callConstructorTest() throws Exception { + + GraphInventoryPayloadException test1 = new GraphInventoryPayloadException("testing"); + + GraphInventoryPayloadException test2 = new GraphInventoryPayloadException("testing", t); + + GraphInventoryPayloadException test3 = new GraphInventoryPayloadException(t); + } + +} diff --git a/common/src/test/java/org/onap/so/client/grm/GRMBeansTest.java b/common/src/test/java/org/onap/so/client/grm/GRMBeansTest.java new file mode 100644 index 0000000000..76b7369399 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/grm/GRMBeansTest.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.grm; + +import java.util.List; + +import org.junit.Test; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.PojoClassFilter; +import com.openpojo.reflection.filters.FilterEnum; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.affirm.Affirm; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +public class GRMBeansTest { + private static final String POJO_PACKAGE = "org.onap.so.client.grm.beans"; + private PojoClassFilter filterTestClasses = new FilterTestClasses(); + + @Test + public void testPojoStructureAndBehavior() { + Validator validator = ValidatorBuilder.create() + .with(new GetterMustExistRule()) + .with(new SetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + + validator.validate(POJO_PACKAGE, new FilterPackageInfo(), new FilterEnum(), filterTestClasses); + } + + private static class FilterTestClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.getSourcePath().contains("/test-classes/"); + } + } + +} diff --git a/common/src/test/java/org/onap/so/client/grm/GRMClientTest.java b/common/src/test/java/org/onap/so/client/grm/GRMClientTest.java new file mode 100644 index 0000000000..3cce6a626b --- /dev/null +++ b/common/src/test/java/org/onap/so/client/grm/GRMClientTest.java @@ -0,0 +1,217 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.grm; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.MediaType; + +import ch.qos.logback.classic.spi.ILoggingEvent; + +import org.apache.log4j.MDC; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.client.grm.beans.OperationalInfo; +import org.onap.so.client.grm.beans.Property; +import org.onap.so.client.grm.beans.ServiceEndPoint; +import org.onap.so.client.grm.beans.ServiceEndPointList; +import org.onap.so.client.grm.beans.ServiceEndPointLookupRequest; +import org.onap.so.client.grm.beans.ServiceEndPointRequest; +import org.onap.so.client.grm.beans.Version; +import org.onap.so.client.grm.exceptions.GRMClientCallFailed; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.tomakehurst.wiremock.junit.WireMockRule; +import org.onap.so.logger.MsoLogger; +import org.onap.so.logger.MsoLogger.Catalog; +import org.onap.so.utils.TestAppender; + +public class GRMClientTest { + + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(47389)); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @BeforeClass + public static void setUp() throws Exception { + System.setProperty("mso.config.path", "src/test/resources"); + } + + private ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testFind() throws Exception { + TestAppender.events.clear(); + String endpoints = getFileContentsAsString("__files/grm/endpoints.json"); + wireMockRule.stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", MediaType.APPLICATION_JSON) + .withHeader("X-FromAppId", "GRM") + .withBody(endpoints))); + + MDC.put(MsoLogger.SERVICE_NAME, "my-value"); + GRMClient client = new GRMClient(); + ServiceEndPointList sel = client.findRunningServices("TEST.ECOMP_PSL.*", 1, "TEST"); + List list = sel.getServiceEndPointList(); + assertEquals(3, list.size()); + ILoggingEvent logEvent = TestAppender.events.get(0); + Map mdc = logEvent.getMDCPropertyMap(); + assertNotNull(mdc.get(MsoLogger.METRIC_BEGIN_TIME)); + assertNotNull(mdc.get(MsoLogger.METRIC_END_TIME)); + assertNotNull(mdc.get(MsoLogger.REQUEST_ID)); + assertNotNull(mdc.get(MsoLogger.METRIC_TIMER)); + assertEquals("200",mdc.get(MsoLogger.RESPONSECODE)); + assertEquals("GRM",mdc.get(MsoLogger.PARTNERNAME)); + assertEquals("expect value to not be overwritten by jax rs client interceptor", "my-value",mdc.get(MsoLogger.SERVICE_NAME)); + assertEquals("COMPLETE",mdc.get(MsoLogger.STATUSCODE)); + assertNotNull(mdc.get(MsoLogger.RESPONSEDESC)); + } + + @Test + public void testFindFail() throws Exception { + + wireMockRule.stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning")) + .willReturn(aResponse() + .withStatus(400) + .withHeader("Content-Type", MediaType.APPLICATION_JSON) + .withBody(""))); + + GRMClient client = new GRMClient(); + thrown.expect(GRMClientCallFailed.class); + client.findRunningServices("TEST.ECOMP_PSL.*", 1, "TEST"); + } + + @Ignore + @Test + public void testAdd() throws Exception { + + wireMockRule.stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/add")) + .willReturn(aResponse() + .withStatus(202) + .withHeader("Content-Type", MediaType.APPLICATION_JSON) + .withBody("test"))); + wireMockRule.addMockServiceRequestListener((request, response) -> { + System.out.println("URL Requested => " + request.getAbsoluteUrl()); + System.out.println("Request Body => " + request.getBodyAsString()); + System.out.println("Request Headers => " + request.getHeaders().toString()); + System.out.println("Response Status => " + response.getStatus()); + System.out.println("Response Body => " + response.getBodyAsString()); + }); + + Version ver = new Version(); + ver.setMajor(1); + ver.setMinor(0); + ver.setPatch("0"); + + ServiceEndPoint sep = new ServiceEndPoint(); + sep.setName("TEST.ECOMP_PSL.Inventory"); + sep.setVersion(ver); + sep.setHostAddress("127.0.0.1"); + sep.setListenPort("8080"); + sep.setLatitude("37.7022"); + sep.setLongitude("121.9358"); + sep.setContextPath("/"); + sep.setRouteOffer("TEST"); + + OperationalInfo operInfo = new OperationalInfo(); + operInfo.setCreatedBy("edge"); + operInfo.setUpdatedBy("edge"); + + sep.setOperationalInfo(operInfo); + + Property prop1 = new Property(); + prop1.setName("Environment"); + prop1.setValue("TEST"); + + Property prop2 = new Property(); + prop2.setName("cpfrun_cluster_name"); + prop2.setValue("testcase_cluster_no_cluster"); + + List props = new ArrayList(); + props.add(prop1); + props.add(prop2); + + sep.setProperties(props); + + ServiceEndPointRequest request = new ServiceEndPointRequest(); + request.setEnv("DEV"); + request.setServiceEndPoint(sep); + + System.out.println("Request in JSON: " + mapper.writeValueAsString(request)); + + GRMClient client = new GRMClient(); + client.addServiceEndPoint(request); + } + + @Test + public void testAddFail() throws Exception { + wireMockRule.stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/add")) + .willReturn(aResponse() + .withStatus(404) + .withHeader("Content-Type", MediaType.APPLICATION_JSON) + .withBody("test"))); + ServiceEndPointRequest request = new ServiceEndPointRequest(); + GRMClient client = new GRMClient(); + thrown.expect(GRMClientCallFailed.class); + client.addServiceEndPoint(request); + } + + @Test + public void testBuildServiceEndPointLookupRequest() { + GRMClient client = new GRMClient(); + ServiceEndPointLookupRequest request = client.buildServiceEndPointlookupRequest("TEST.ECOMP_PSL.Inventory", 1, "DEV"); + assertEquals("TEST.ECOMP_PSL.Inventory", request.getServiceEndPoint().getName()); + assertEquals(Integer.valueOf(1), Integer.valueOf(request.getServiceEndPoint().getVersion().getMajor())); + assertEquals("DEV", request.getEnv()); + + } + + protected String getFileContentsAsString(String fileName) { + String content = ""; + try { + ClassLoader classLoader = this.getClass().getClassLoader(); + File file = new File(classLoader.getResource(fileName).getFile()); + content = new String(Files.readAllBytes(file.toPath())); + } + catch(Exception e) { + e.printStackTrace(); + System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage()); + } + return content; + } +} diff --git a/common/src/test/java/org/onap/so/client/grm/ServiceEndPointListTest.java b/common/src/test/java/org/onap/so/client/grm/ServiceEndPointListTest.java new file mode 100644 index 0000000000..a1fb43ea5e --- /dev/null +++ b/common/src/test/java/org/onap/so/client/grm/ServiceEndPointListTest.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.grm; + +import java.io.File; +import java.nio.file.Files; +import java.util.List; +import static org.junit.Assert.*; +import org.junit.Test; +import org.onap.so.client.grm.beans.ServiceEndPoint; +import org.onap.so.client.grm.beans.ServiceEndPointList; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ServiceEndPointListTest { + + private ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testUnmarshall() throws Exception { + String endpointsJson = getFileContentsAsString("__files/grm/endpoints.json"); + ServiceEndPointList sel = mapper.readValue(endpointsJson, ServiceEndPointList.class); + + List list = sel.getServiceEndPointList(); + ServiceEndPoint se = list.get(0); + + assertEquals(3, list.size()); + assertEquals("dummy.pod.ns.dummy-pod3", se.getName()); + assertEquals(Integer.valueOf(1), Integer.valueOf(se.getVersion().getMajor())); + assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getMinor())); + assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getPatch())); + assertEquals("192.168.120.218", se.getHostAddress()); + assertEquals("32004", se.getListenPort()); + assertEquals("37.7022", se.getLatitude()); + assertEquals("121.9358", se.getLongitude()); + assertEquals("/", se.getContextPath()); + assertEquals("edge", se.getOperationalInfo().getCreatedBy()); + assertEquals("edge", se.getOperationalInfo().getUpdatedBy()); + assertEquals("Environment", se.getProperties().get(0).getName()); + assertEquals("DEV", se.getProperties().get(0).getValue()); + } + + protected String getFileContentsAsString(String fileName) { + + String content = ""; + try { + ClassLoader classLoader = this.getClass().getClassLoader(); + File file = new File(classLoader.getResource(fileName).getFile()); + content = new String(Files.readAllBytes(file.toPath())); + } + catch(Exception e) { + e.printStackTrace(); + System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage()); + } + return content; + } +} diff --git a/common/src/test/java/org/onap/so/client/grm/ServiceEndPointRequestTest.java b/common/src/test/java/org/onap/so/client/grm/ServiceEndPointRequestTest.java new file mode 100644 index 0000000000..4fe6bca05e --- /dev/null +++ b/common/src/test/java/org/onap/so/client/grm/ServiceEndPointRequestTest.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.grm; + +import static org.junit.Assert.assertEquals; +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; +import org.onap.so.client.grm.beans.OperationalInfo; +import org.onap.so.client.grm.beans.Property; +import org.onap.so.client.grm.beans.ServiceEndPoint; +import org.onap.so.client.grm.beans.ServiceEndPointRequest; +import org.onap.so.client.grm.beans.Version; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ServiceEndPointRequestTest { + + private ObjectMapper mapper = new ObjectMapper(); + + @Test + public void testMarshall() throws Exception { + + String expected = + "{\"serviceEndPoint\":{\"name\":\"TEST.ECOMP_PSL.Inventory\",\"version\":{\"major\":1,\"minor\":0,\"patch\":\"0\"}," + + "\"hostAddress\":\"127.0.0.1\",\"listenPort\":\"8080\",\"latitude\":\"37.7022\",\"longitude\":\"121.9358\"," + + "\"contextPath\":\"/\",\"routeOffer\":\"TEST\",\"operationalInfo\":{\"createdBy\":\"edge\",\"updatedBy\":\"edge\"}," + + "\"properties\":[{\"name\":\"Environment\",\"value\":\"TEST\"},{\"name\":\"cpfrun_cluster_name\"," + + "\"value\":\"testcase_cluster_no_cluster\"}]},\"env\":\"DEV\"}"; + + Version ver = new Version(); + ver.setMajor(1); + ver.setMinor(0); + ver.setPatch("0"); + + ServiceEndPoint sep = new ServiceEndPoint(); + sep.setName("TEST.ECOMP_PSL.Inventory"); + sep.setVersion(ver); + sep.setHostAddress("127.0.0.1"); + sep.setListenPort("8080"); + sep.setLatitude("37.7022"); + sep.setLongitude("121.9358"); + sep.setContextPath("/"); + sep.setRouteOffer("TEST"); + + OperationalInfo operInfo = new OperationalInfo(); + operInfo.setCreatedBy("edge"); + operInfo.setUpdatedBy("edge"); + + sep.setOperationalInfo(operInfo); + + Property prop1 = new Property(); + prop1.setName("Environment"); + prop1.setValue("TEST"); + + Property prop2 = new Property(); + prop2.setName("cpfrun_cluster_name"); + prop2.setValue("testcase_cluster_no_cluster"); + + List props = new ArrayList(); + props.add(prop1); + props.add(prop2); + + sep.setProperties(props); + + ServiceEndPointRequest request = new ServiceEndPointRequest(); + request.setEnv("DEV"); + request.setServiceEndPoint(sep); + + assertEquals(expected, mapper.writeValueAsString(request)); + } +} diff --git a/common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java b/common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java new file mode 100644 index 0000000000..104d40f76e --- /dev/null +++ b/common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.policy; + +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.doReturn; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.so.client.defaultproperties.PolicyRestPropertiesImpl; +import org.onap.so.client.policy.entities.DictionaryData; +import org.onap.so.client.policy.entities.PolicyDecision; +import org.onap.so.client.policy.entities.PolicyServiceType; + +public class PolicyClientImplTest { + + @BeforeClass + public static void setUp() { + System.setProperty("mso.config.path", "src/test/resources"); + } + @Test + public void successReadProperties() { + PolicyRestClient client = new PolicyRestClient(new PolicyRestPropertiesImpl(), PolicyServiceType.GET_DECISION); + Map map = new HashMap<>(); + client.initializeHeaderMap(map); + assertEquals("Found expected Client Auth", "Basic bTAzNzQzOnBvbGljeVIwY2sk", map.get("ClientAuth")); + assertEquals("Found expected Authorization", "Basic dGVzdHBkcDphbHBoYTEyMw==", map.get("Authorization")); + assertEquals("Found expected Environment", "TEST", map.get("Environment")); + } + + @Test + @Ignore + public void getDecisionTest() { + PolicyClient client = new PolicyClientImpl(); + PolicyDecision decision = client.getDecision("S", "V", "BB1", "1", "123"); + assertEquals("Decision is correct", decision.getDecision(), "PERMIT"); + assertEquals("Decision details is correct", decision.getDetails(), "Retry"); + } + + @Test + @Ignore + public void getAllowedTreatmentsTest(){ + PolicyClient client = new PolicyClientImpl(); + DictionaryData dictClient = client.getAllowedTreatments("BB1", "1"); + final String dictBbidString = dictClient.getBbid().getString(); + final String dictWorkStepString = dictClient.getWorkstep().getString(); + assertEquals("DictionaryData matches a response Bbid", dictBbidString, "BB1"); + assertEquals("DicitonaryData matches a response WorkStep", dictWorkStepString, "1"); + } + + @Test + public void getDecisionMockTest() { + String serviceType = "S"; + String vnfType = "V"; + String bbID = "BB1"; + String workStep = "1"; + String errorCode = "123"; + + PolicyDecision expected = new PolicyDecision(); + expected.setDecision("PERMIT"); + expected.setDetails("Retry"); + + DecisionAttributes decisionAttributes = new DecisionAttributes(); + decisionAttributes.setServiceType(serviceType); + decisionAttributes.setVNFType(vnfType); + decisionAttributes.setBBID(bbID); + decisionAttributes.setWorkStep(workStep); + decisionAttributes.setErrorCode(errorCode); + PolicyClient client = Mockito.spy(PolicyClientImpl.class); + + doReturn(expected).when(client).getDecision(serviceType, vnfType, bbID, workStep, errorCode); + + PolicyDecision actual = client.getDecision(serviceType, vnfType, bbID, workStep, errorCode); + assertThat(actual, sameBeanAs(expected)); + } + + /* + @Test + public void getAllowedTreatmentsTest() { + PolicyClient client = new PolicyClientImpl(); + AllowedTreatments allowedTreatments = client.getAllowedTreatments("BB1", "1"); + int expectedSizeOfList = 4; + int sizeOfList = allowedTreatments.getAllowedTreatments().size(); + assertEquals("Decision is correct", sizeOfList, expectedSizeOfList); + }*/ +} diff --git a/common/src/test/java/org/onap/so/client/policy/entities/PolicyEntitiesTest.java b/common/src/test/java/org/onap/so/client/policy/entities/PolicyEntitiesTest.java new file mode 100644 index 0000000000..2796affa49 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/policy/entities/PolicyEntitiesTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.policy.entities; + +import org.junit.Test; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.PojoClassFilter; +import com.openpojo.reflection.filters.FilterEnum; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +public class PolicyEntitiesTest { + + private PojoClassFilter filterTestClasses = new FilterTestClasses(); + + @Test + public void pojoStructure() { + test("org.onap.so.client.policy.entities"); + } + + private void test(String pojoPackage) { + Validator validator = ValidatorBuilder.create() + .with(new GetterMustExistRule()) + .with(new SetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses); + } + private static class FilterTestClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.getSourcePath().contains("/test-classes/"); + } + } +} diff --git a/common/src/test/java/org/onap/so/client/ruby/RubyCheckClientTest.java b/common/src/test/java/org/onap/so/client/ruby/RubyCheckClientTest.java new file mode 100644 index 0000000000..ba8772b05c --- /dev/null +++ b/common/src/test/java/org/onap/so/client/ruby/RubyCheckClientTest.java @@ -0,0 +1,106 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.ruby; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.text.ParseException; +import java.time.format.DateTimeFormatter; + +import org.junit.Test; +import org.onap.so.client.ruby.beans.Ruby; + +import static org.apache.commons.lang3.StringUtils.*; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class RubyCheckClientTest { + private final String fileLocation = "src/test/resources/org/onap/so/client/ruby/create-ticket/"; + private static final String REQUEST_ID = "abc123"; + private static final String SOURCE_NAME = "source-name"; + private static final String TIME = "test-time"; + private static final String REASON = "reason"; + private static final String WORK_FLOW_ID = "work-flow-Id"; + private static final String NOTIFICATION = "notification"; + + + + @Test + public void verifyRubyCreateTicketRequest() throws IOException, ParseException{ + String content = this.getJson("create-ticket-request.json"); + ObjectMapper mapper = new ObjectMapper(); + Ruby expected = mapper.readValue(content, Ruby.class); + RubyClient client = new RubyClient(); + RubyClient spy = spy(client); + when(spy.getTime()).thenReturn(TIME); + String actual = spy.buildRequest(REQUEST_ID, SOURCE_NAME, REASON, WORK_FLOW_ID, NOTIFICATION); + assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); + } + + + @Test + public void verifyTimeFormat() { + RubyClient client = new RubyClient(); + String time = client.getTime(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss Z"); + formatter.parse(time); + } + + + @Test + public void verifyReasonCharLimit() throws IOException{ + final String reasonLong = repeat("*", 256); + RubyClient client = new RubyClient(); + try{ + client.buildRequest(REQUEST_ID, SOURCE_NAME, reasonLong, WORK_FLOW_ID, NOTIFICATION); + fail("Should have thrown IllegalArgumentException but did not!"); + } + catch(final IllegalArgumentException e){ + final String msg = "reason exceeds 255 characters"; + assertEquals(msg, e.getMessage()); + } + } + + @Test + public void verifyNotificationCharLimit() throws IOException{ + final String notificationLong = repeat("*", 1025); + RubyClient client = new RubyClient(); + try{ + client.buildRequest(REQUEST_ID, SOURCE_NAME, REASON, WORK_FLOW_ID, notificationLong); + fail("Should have thrown IllegalArgumentException but did not!"); + } + catch(final IllegalArgumentException e){ + final String msg = "notification exceeds 1024 characters"; + assertEquals(msg, e.getMessage()); + } + } + + private String getJson(String filename) throws IOException { + return new String(Files.readAllBytes(Paths.get(fileLocation + filename))); + } + +} + diff --git a/common/src/test/java/org/onap/so/client/ruby/beans/RubyBeansTest.java b/common/src/test/java/org/onap/so/client/ruby/beans/RubyBeansTest.java new file mode 100644 index 0000000000..eb142be4c6 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/ruby/beans/RubyBeansTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.ruby.beans; + +import org.junit.Test; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.PojoClassFilter; +import com.openpojo.reflection.filters.FilterEnum; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +public class RubyBeansTest { + + private PojoClassFilter filterTestClasses = new FilterTestClasses(); + + @Test + public void pojoStructure() { + test("org.onap.so.client.ruby.beans"); + } + + private void test(String pojoPackage) { + Validator validator = ValidatorBuilder.create() + .with(new GetterMustExistRule()) + .with(new SetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses); + } + private static class FilterTestClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.getSourcePath().contains("/test-classes/"); + } + } +} diff --git a/common/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java b/common/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java new file mode 100644 index 0000000000..4887aed522 --- /dev/null +++ b/common/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdno; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Optional; + +import org.junit.Test; +import org.onap.so.client.sdno.beans.SDNO; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class SDNOHealthCheckClientTest { + + + + private final String fileLocation = "src/test/resources/org/onap/so/client/sdno/health-check/"; + private static final String userId = "test-user"; + private static final Optional clliCode = Optional.of("test-clli"); + private static final String requestId = "test-request-id"; + private static final String configurationId = "test-configuration-id"; + private static final String interfaceId = "test-interface-id"; + + @Test + public void verfyLPortMirrorPreCheckRequest() throws IOException{ + String content = this.getJson("custom-lport-mirror-pre-check-request.json"); + ObjectMapper mapper = new ObjectMapper(); + SDNO expected = mapper.readValue(content, SDNO.class); + SDNOHealthCheckClient client = new SDNOHealthCheckClient(); + String actual = client.buildLPortMirrorCheckPreRequest(userId, requestId, clliCode, configurationId, interfaceId); + assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); + } + + @Test + public void verfyLPortMirrorPostCheckRequest() throws IOException{ + String content = this.getJson("custom-lport-mirror-post-check-request.json"); + ObjectMapper mapper = new ObjectMapper(); + SDNO expected = mapper.readValue(content, SDNO.class); + SDNOHealthCheckClient client = new SDNOHealthCheckClient(); + String actual = client.buildLPortMirrorCheckPostRequest(userId, requestId, clliCode, configurationId, interfaceId); + assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); + } + + + @Test + public void verifyPortMirrorPostCheckRequest() throws IOException{ + String content = this.getJson("custom-port-mirror-post-check-request.json"); + ObjectMapper mapper = new ObjectMapper(); + SDNO expected = mapper.readValue(content, SDNO.class); + SDNOHealthCheckClient client = new SDNOHealthCheckClient(); + String actual = client.buildPortMirrorPostCheckRequest(userId, requestId, clliCode, configurationId); + + assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); + + } + @Test + public void verifyPortMirrorPreCheckRequest() throws IOException { + String content = this.getJson("custom-port-mirror-pre-check-request.json"); + ObjectMapper mapper = new ObjectMapper(); + SDNO expected = mapper.readValue(content, SDNO.class); + SDNOHealthCheckClient client = new SDNOHealthCheckClient(); + String actual = client.buildPortMirrorPreCheckRequest(userId, requestId, clliCode, configurationId); + + assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); + + } + + private String getJson(String filename) throws IOException { + return new String(Files.readAllBytes(Paths.get(fileLocation + filename))); + } + +} diff --git a/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorTest.java b/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorTest.java new file mode 100644 index 0000000000..89dd2f554f --- /dev/null +++ b/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorTest.java @@ -0,0 +1,116 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdno; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.UUID; + +import org.hamcrest.core.StringContains; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.so.client.dmaap.Consumer; +import org.onap.so.client.dmaap.exceptions.DMaaPConsumerFailure; +import org.onap.so.client.exceptions.SDNOException; +import org.onap.so.client.sdno.beans.SDNO; +import org.onap.so.client.sdno.dmaap.SDNOHealthCheckDmaapConsumer; + +import com.fasterxml.jackson.databind.ObjectMapper; + + +public class SDNOValidatorTest { + + + @Mock private Consumer mrConsumer; + @Spy private SDNOHealthCheckDmaapConsumer dmaapConsumer; + private final String fileLocation = "src/test/resources/org/onap/so/client/sdno/"; + private final String uuid = "xyz123"; + @Rule public ExpectedException thrown = ExpectedException.none(); + + @Before + public void setUpTests() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void success() throws IOException, Exception { + when(dmaapConsumer.getConsumer()).thenReturn(mrConsumer); + when(mrConsumer.fetch()).thenReturn(Arrays.asList(new String[]{getJson("response.json"), getJson("output-success.json")})); + + SDNOValidatorImpl validator = new SDNOValidatorImpl(); + SDNOValidatorImpl spy = spy(validator); + when(dmaapConsumer.getRequestId()).thenReturn("xyz123"); + doReturn(dmaapConsumer).when(spy).getConsumer(any(String.class)); + boolean result = spy.pollForResponse("xyz123"); + assertEquals("result is true", result, true); + } + + @Test + public void failure() throws IOException, Exception { + when(dmaapConsumer.getConsumer()).thenReturn(mrConsumer); + when(mrConsumer.fetch()).thenReturn(Arrays.asList(new String[]{getJson("response.json"), getJson("output-failure.json")})); + + SDNOValidatorImpl validator = new SDNOValidatorImpl(); + SDNOValidatorImpl spy = spy(validator); + when(dmaapConsumer.getRequestId()).thenReturn("xyz123"); + doReturn(dmaapConsumer).when(spy).getConsumer(any(String.class)); + thrown.expect(SDNOException.class); + thrown.expectMessage(new StringContains("my error message")); + boolean result = spy.pollForResponse("xyz123"); + + } + @Ignore + @Test + public void run() throws Exception { + SDNOValidatorImpl validator = new SDNOValidatorImpl(); + UUID uuid = UUID.randomUUID(); + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("test"); + vnf.setIpv4OamAddress("1.2.3.4"); + vnf.setVnfType("VPE"); + SDNO request = validator.buildRequestDiagnostic(vnf, uuid, "mechid"); + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(request); + validator.submitRequest(json); + thrown.expect(DMaaPConsumerFailure.class); + boolean result = validator.pollForResponse(uuid.toString()); + System.out.println(json); + + } + private String getJson(String filename) throws IOException { + return new String(Files.readAllBytes(Paths.get(fileLocation + filename))); + } +} diff --git a/common/src/test/java/org/onap/so/client/sdno/beans/SdnoBeansTest.java b/common/src/test/java/org/onap/so/client/sdno/beans/SdnoBeansTest.java new file mode 100644 index 0000000000..bdfefd028c --- /dev/null +++ b/common/src/test/java/org/onap/so/client/sdno/beans/SdnoBeansTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdno.beans; + +import org.junit.Test; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.PojoClassFilter; +import com.openpojo.reflection.filters.FilterEnum; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +public class SdnoBeansTest { + + private PojoClassFilter filterTestClasses = new FilterTestClasses(); + + @Test + public void pojoStructure() { + test("org.onap.so.client.sdno.beans"); + } + + private void test(String pojoPackage) { + Validator validator = ValidatorBuilder.create() + .with(new GetterMustExistRule()) + .with(new SetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses); + } + private static class FilterTestClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.getSourcePath().contains("/test-classes/"); + } + } +} diff --git a/common/src/test/java/org/onap/so/entity/MsoRequestTest.java b/common/src/test/java/org/onap/so/entity/MsoRequestTest.java new file mode 100644 index 0000000000..73b5c7ea2d --- /dev/null +++ b/common/src/test/java/org/onap/so/entity/MsoRequestTest.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.entity; + +import org.junit.Test; +import org.onap.so.openpojo.rules.HasToStringRule; +import org.onap.so.openpojo.rules.ToStringTester; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.PojoClassFilter; +import com.openpojo.reflection.filters.FilterEnum; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + + +public class MsoRequestTest { + + private PojoClassFilter filterTestClasses = new FilterTestClasses(); + + @Test + public void pojoStructure() { + test("org.onap.so.entity"); + } + + private void test(String pojoPackage) { + Validator validator = ValidatorBuilder.create() + .with(new GetterMustExistRule()) + .with(new SetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses); + } + private static class FilterTestClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.getSourcePath().contains("/test-classes/"); + } + } + +} + diff --git a/common/src/test/java/org/onap/so/exceptions/ValidationExceptionTest.java b/common/src/test/java/org/onap/so/exceptions/ValidationExceptionTest.java new file mode 100644 index 0000000000..b3ae7ba9f5 --- /dev/null +++ b/common/src/test/java/org/onap/so/exceptions/ValidationExceptionTest.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.exceptions; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by ANANDSAN on 4/12/2018. + */ +public class ValidationExceptionTest { + @Test + public void validationExceptionOverrideMessageFalse(){ + ValidationException e = new ValidationException("testMessage", false); + Assert.assertEquals("testMessage", e.getMessage()); + } + + @Test + public void validationExceptionOverrideMessageTrue(){ + ValidationException e = new ValidationException("testMessage", true); + Assert.assertEquals("No valid testMessage is specified", e.getMessage()); + } + + @Test + public void validationException(){ + ValidationException e = new ValidationException("testMessage"); + Assert.assertEquals("No valid testMessage is specified", e.getMessage()); + } + + @Test + public void validationExceptionVersion(){ + ValidationException e = new ValidationException("testMessage", "1.0"); + Assert.assertEquals("testMessage is not valid in the 1.0 version", e.getMessage()); + } +} diff --git a/common/src/test/java/org/onap/so/jsonpath/JsonPathUtilTest.java b/common/src/test/java/org/onap/so/jsonpath/JsonPathUtilTest.java new file mode 100644 index 0000000000..06e25daa98 --- /dev/null +++ b/common/src/test/java/org/onap/so/jsonpath/JsonPathUtilTest.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.jsonpath; + +import static org.junit.Assert.assertEquals; + +import java.util.Collections; +import java.util.Optional; + +import org.junit.Test; + +public class JsonPathUtilTest { + + private static final String json = "{\"test\" : \"hello\", \"test2\" : {\"nested\" : \"value\"}}"; + @Test + public void pathExistsTest() { + assertEquals("test is found", JsonPathUtil.getInstance().pathExists(json, "$.test"), true); + assertEquals("nothing is not found", JsonPathUtil.getInstance().pathExists(json, "$.nothing"), false); + } + + @Test + public void locateResultTest() { + assertEquals("value of hello is found", Optional.of("hello"), JsonPathUtil.getInstance().locateResult(json, "$.test")); + assertEquals("nothing returns empty", Optional.empty(), JsonPathUtil.getInstance().locateResult(json, "$.nothing")); + } + + @Test + public void simpleAndComplexValues() { + assertEquals("json doc found", Optional.of("{\"nested\":\"value\"}"), JsonPathUtil.getInstance().locateResult(json, "$.test2")); + assertEquals("value found", Optional.of("value"), JsonPathUtil.getInstance().locateResult(json, "$.test2.nested")); + } + + @Test + public void pathListTest() { + assertEquals(Collections.singletonList("$['test2']['nested']"), JsonPathUtil.getInstance().getPathList(json, "$.*.*")); + } +} diff --git a/common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstanceBeansTest.java b/common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstanceBeansTest.java new file mode 100644 index 0000000000..7a4af7808e --- /dev/null +++ b/common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstanceBeansTest.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.serviceinstancebeans; + +import org.junit.Test; +import org.onap.so.openpojo.rules.HasToStringRule; +import org.onap.so.openpojo.rules.ToStringTester; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.PojoClassFilter; +import com.openpojo.reflection.filters.FilterEnum; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +public class ServiceInstanceBeansTest { + + private PojoClassFilter filterTestClasses = new FilterTestClasses(); + + @Test + public void pojoStructure() { + test("org.onap.so.serviceinstancebeans"); + } + + private void test(String pojoPackage) { + Validator validator = ValidatorBuilder.create() + .with(new GetterMustExistRule()) + .with(new SetterMustExistRule()) + .with(new HasToStringRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .with(new ToStringTester()) + .build(); + validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses); + } + private static class FilterTestClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.getSourcePath().contains("/test-classes/"); + } + } + +} diff --git a/common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstancesRequestTest.java b/common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstancesRequestTest.java new file mode 100644 index 0000000000..2e67ff4b2b --- /dev/null +++ b/common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstancesRequestTest.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.serviceinstancebeans; + +import org.junit.Assert; +import org.junit.Test; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ServiceInstancesRequestTest { + + @Test + public void serializeServiceInstance() { + String incomingRequest = "{\"requestDetails\":{\"modelInfo\":{\"modelInvariantUuid\":\"9647dfc4-2083-11e7-93ae-92361f002672\",\"modelType\":\"configuration\",\"modelName\":\"MSO-Configuration\",\"modelVersion\":\"1.0\",\"modelUuid\":\"36a3a8ea-49a6-4ac8-b06c-89a545444455\",\"modelCustomizationUuid\":\"68dc9a92-214c-11e7-93ae-92361f002671\"},\"requestInfo\":{\"source\":\"VID\",\"instanceName\":\"port_mirror_config_m830-01\",\"suppressRollback\":false,\"requestorId\":\"mdg1215\"},\"relatedInstanceList\":[{\"relatedInstance\":{\"instanceId\":\"956121e0-542d-4b30-b8c7-be611e3c8f13\",\"modelInfo\":{\"modelInvariantUuid\":\"9647dfc4-2083-11e7-93ae-92361f002671\",\"modelType\":\"service\",\"modelName\":\"MSOTADevInfra_vSAMP10a_Service\",\"modelVersion\":\"1.0\",\"modelUuid\":\"5df8b6de-2083-11e7-93ae-92361f002671\"}}},{\"relatedInstance\":{\"instanceId\":\"956121e0-542d-4b30-b8c7-be611e3c8f11\",\"modelInfo\":{\"modelInvariantUuid\":\"36a3a8ea-49a6-4ac8-b06c-89a545444456\",\"modelType\":\"vnf\",\"modelName\":\"testvnf\",\"modelVersion\":\"1.0\",\"modelUuid\":\"956121e0-542d-4b30-b8c7-be611e3c8f14\",\"modelCustomizationUuid\":\"68dc9a92-214c-11e7-93ae-92361f002676\"},\"instanceDirection\":\"source\"}},{\"relatedInstance\":{\"instanceId\":\"956121e0-542d-4b30-b8c7-be611e3c8f12\",\"modelInfo\":{\"modelInvariantUuid\":\"36a3a8ea-49a6-4ac8-b06c-89a545444477\",\"modelType\":\"vnf\",\"modelName\":\"svProbe vnf model name\",\"modelVersion\":\"1.0\",\"modelUuid\":\"36a3a8ea-49a6-4ac8-b06c-89a545444488\",\"modelCustomizationUuid\":\"68dc9a92-214c-11e7-93ae-92361f002672\"},\"instanceDirection\":\"destination\"}}],\"cloudConfiguration\":{\"lcpCloudRegionId\":\"mdt1\"},\"requestParameters\":{\"subscriptionServiceType\":\"MSO-dev-service-type\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"}],\"aLaCarte\":false,\"autoBuildVfModules\":false,\"cascadeDelete\":false,\"usePreload\":true,\"rebuildVolumeGroups\":false}},\"serviceInstanceId\":\"956121e0-542d-4b30-b8c7-be611e3c8f13\"}"; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + try { + ServiceInstancesRequest request = mapper.readValue(incomingRequest, ServiceInstancesRequest.class); + System.out.println("Java Object: " + request); + } catch (Exception e) { + System.out.println("Caught Exception " + e.getMessage()); + Assert.fail("Caught error on object serialization"); + } + } +} diff --git a/common/src/test/java/org/onap/so/utils/CheckResultsTest.java b/common/src/test/java/org/onap/so/utils/CheckResultsTest.java new file mode 100644 index 0000000000..0e1da16b9e --- /dev/null +++ b/common/src/test/java/org/onap/so/utils/CheckResultsTest.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.utils; + +import static org.junit.Assert.*; + +import java.util.List; + +import org.junit.Test; + +import org.onap.so.utils.CheckResults.CheckResult; + +public class CheckResultsTest { + + /** + * Test method for {@link org.onap.so.utils.CheckResults#getResults()}. + */ + @Test + public final void testGetResults () { + CheckResults cr = new CheckResults (); + cr.addHostCheckResult ("host1", 0, "output"); + cr.addHostCheckResult ("host2", 2, "output2"); + cr.addServiceCheckResult ("host1", "service1", 0, "outputServ"); + cr.addServiceCheckResult ("host1", "service2", 2, "outputServ2"); + cr.addServiceCheckResult ("host2", "service1", 0, "output2Serv"); + cr.addServiceCheckResult ("host2", "service2", 2, "output2Serv2"); + List res = cr.getResults (); + assertEquals(res.size (), 6); + assertEquals(res.get (0).getHostname (), "host1"); + assertEquals(res.get (1).getHostname (), "host2"); + assertEquals(res.get (2).getHostname (), "host1"); + assertEquals(res.get (3).getHostname (), "host1"); + assertEquals(res.get (4).getHostname (), "host2"); + assertEquals(res.get (5).getHostname (), "host2"); + assertEquals(res.get (0).getServicename (), null); + assertEquals(res.get (3).getServicename (), "service2"); + assertEquals(res.get (5).getState (), 2); + } + +} diff --git a/common/src/test/java/org/onap/so/utils/TestAppender.java b/common/src/test/java/org/onap/so/utils/TestAppender.java new file mode 100644 index 0000000000..fba9c71c68 --- /dev/null +++ b/common/src/test/java/org/onap/so/utils/TestAppender.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.utils; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.AppenderBase; + +import java.util.ArrayList; +import java.util.List; + + +public class TestAppender extends AppenderBase { + public static List events = new ArrayList<>(); + + @Override + protected void append(ILoggingEvent loggingEvent) { + if (loggingEvent.getLevel() == Level.INFO) { + events.add(loggingEvent); + } + } + +} diff --git a/common/src/test/java/org/onap/so/utils/UUIDCheckerTest.java b/common/src/test/java/org/onap/so/utils/UUIDCheckerTest.java new file mode 100644 index 0000000000..b4058a7ba8 --- /dev/null +++ b/common/src/test/java/org/onap/so/utils/UUIDCheckerTest.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.utils; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.so.logger.MsoLogger; + +public class UUIDCheckerTest { + private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL, UUIDCheckerTest.class); + + @Test + public void isValidUUIDTest(){ + String nullID = null; + String badID = "This is not a UUID"; + String id = UUIDChecker.getUUID(); + assertFalse(UUIDChecker.isValidUUID(nullID)); + assertFalse(UUIDChecker.isValidUUID(badID)); + assertTrue(UUIDChecker.isValidUUID(id)); + } + + @Test + public void verifyOldUUIDTest(){ + String oldID = UUIDChecker.getUUID(); + String invalidID = "This is not a UUID"; + assertEquals(UUIDChecker.verifyOldUUID(oldID,LOGGER),oldID); + assertNotEquals(UUIDChecker.verifyOldUUID(invalidID,LOGGER),invalidID); + } + + @Test + public void generateTest(){ + String id = UUIDChecker.generateUUID(LOGGER); + assertNotNull(id); + assertTrue(UUIDChecker.isValidUUID(id)); + + id = UUIDChecker.generateServiceInstanceID(LOGGER); + assertNotNull(id); + assertTrue(UUIDChecker.isValidUUID(id)); + + } +} diff --git a/common/src/test/java/org/onap/so/utils/XMLMarshallerTest.java b/common/src/test/java/org/onap/so/utils/XMLMarshallerTest.java new file mode 100644 index 0000000000..148e1b452c --- /dev/null +++ b/common/src/test/java/org/onap/so/utils/XMLMarshallerTest.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.utils; + +import org.junit.Assert; +import org.junit.Test; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Tests the XMLMarshaller to ensure that it's able to marshal and unmarshall a POJO + */ + +public class XMLMarshallerTest { + + @Test + public void testMarshal() throws Exception { + Assert.assertEquals(getXML(), XmlMarshaller.marshal(getPOJO())); + } + + @Test + public void testUnMarshal() throws Exception { + Assert.assertEquals(XmlMarshaller.unMarshal(getXML(), new TestPOJO()), getPOJO()); + } + + private TestPOJO getPOJO() { + TestPOJO testPOJO = new TestPOJO(); + testPOJO.setFirstName("FN"); + testPOJO.setLastName("LN"); + return testPOJO; + } + + private String getXML() { + return "FNLN"; + } + + @XmlRootElement + static class TestPOJO { + String firstName; + String lastName; + + public TestPOJO() { + } + + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof TestPOJO)) return false; + + TestPOJO testPOJO = (TestPOJO) o; + + if (getFirstName() != null ? !getFirstName().equals(testPOJO.getFirstName()) : testPOJO.getFirstName() != null) + return false; + return getLastName() != null ? getLastName().equals(testPOJO.getLastName()) : testPOJO.getLastName() == null; + } + + @Override + public int hashCode() { + int result = getFirstName() != null ? getFirstName().hashCode() : 0; + result = 31 * result + (getLastName() != null ? getLastName().hashCode() : 0); + return result; + } + } + + +} diff --git a/common/src/test/java/org/onap/so/web/exceptions/RuntimeExceptionMapperTest.java b/common/src/test/java/org/onap/so/web/exceptions/RuntimeExceptionMapperTest.java new file mode 100644 index 0000000000..8bcc73515b --- /dev/null +++ b/common/src/test/java/org/onap/so/web/exceptions/RuntimeExceptionMapperTest.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.web.exceptions; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +import javax.ws.rs.NotFoundException; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; + +import org.junit.AfterClass; +import org.junit.Test; +import org.onap.so.logger.MsoAlarmLogger; + +public class RuntimeExceptionMapperTest { + + + @AfterClass + public static void tearDown() { + MsoAlarmLogger logger = new MsoAlarmLogger(); + logger.resetAppender(); + } + + @Test + public void testResponse() { + + RuntimeExceptionMapper mapper = new RuntimeExceptionMapper(); + + Response r = mapper.toResponse(new RuntimeException("This is the run time exception message")); + + assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus()); + assertThat(r.getEntity(), instanceOf(ExceptionResponse.class)); + assertThat(((ExceptionResponse)r.getEntity()).getMessage(), equalTo("Unexpected Internal Exception")); + + } + + @Test + public void preserve404ExceptionForForwarding() { + + RuntimeExceptionMapper mapper = new RuntimeExceptionMapper(); + + Response r = mapper.toResponse(new NotFoundException("not found")); + + assertEquals(Status.NOT_FOUND.getStatusCode(), r.getStatus()); + assertThat(r.getEntity(), is(nullValue())); + } + +} diff --git a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/CryptoTest.java b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/CryptoTest.java deleted file mode 100644 index 3415420c88..0000000000 --- a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/CryptoTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.adapter_utils.tests; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.security.GeneralSecurityException; - -import org.junit.BeforeClass; -import org.junit.Test; - -import org.openecomp.mso.utils.CryptoUtils; - -/** - * This class implements all test methods of the CryptoUtils features. - * - * - */ -public class CryptoTest { - - private static String testKey = "546573746F736973546573746F736973"; - - /** - * This method is called before any test occurs. - * It creates a fake tree from scratch - */ - @BeforeClass - public static final void prepare () { - - } - - /** - * This method implements a test of tree structure, mainly the storage of the leaves structure. - * @throws GeneralSecurityException - */ - @Test - public final void testEncryption () throws GeneralSecurityException { - String hexString = CryptoUtils.byteArrayToHexString("testosistestosi".getBytes()); - - final String testData = "This is a test string"; - final String nonTestData = "This is not the right String"; - - String encodeString = CryptoUtils.encrypt(testData, testKey); - - assertNotNull(encodeString); - - assertTrue(testData.equals(CryptoUtils.decrypt(encodeString, testKey))); - assertFalse(nonTestData.equals(CryptoUtils.decrypt(encodeString, testKey))); - - String encode2String = CryptoUtils.encrypt(testData, testKey); - assertNotNull(encode2String); - - assertEquals(encodeString,encode2String); - - assertEquals(CryptoUtils.decrypt(encodeString, testKey),CryptoUtils.decrypt(encode2String, testKey)); - } - -} diff --git a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoAlarmLoggerTest.java b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoAlarmLoggerTest.java deleted file mode 100644 index f7d27acaf3..0000000000 --- a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoAlarmLoggerTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.adapter_utils.tests; - - -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintWriter; - -import org.junit.BeforeClass; -import org.junit.Test; - -import org.openecomp.mso.logger.MsoAlarmLogger; -import org.openecomp.mso.properties.MsoJavaProperties; -import org.openecomp.mso.properties.MsoPropertiesException; -import org.openecomp.mso.properties.MsoPropertiesFactory; - -/** - * This junit test very roughly the alarm logger - * - */ -public class MsoAlarmLoggerTest { - - public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); - public static MsoAlarmLogger msoAlarmLogger; - - @BeforeClass - public static final void createObjects() throws MsoPropertiesException - { - - File outputFile = new File ("target/alarm-test.log"); - if (outputFile.exists()) { - outputFile.delete(); - } - msoAlarmLogger = new MsoAlarmLogger("target/alarm-test.log"); - } - - @Test - public void testAlarmConfig() throws MsoPropertiesException, IOException { - - msoAlarmLogger.sendAlarm("test", 0, "detail message"); - - FileInputStream inputStream = new FileInputStream("target/alarm-test.log"); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - - String line = reader.readLine(); - String[] splitLine = line.split("\\|"); - assertTrue(splitLine.length==4); - assertTrue("test".equals(splitLine[1])); - assertTrue("0".equals(splitLine[2])); - assertTrue("detail message".equals(splitLine[3])); - - line = reader.readLine(); - assertNull(line); - reader.close(); - inputStream.close(); - - // Reset the file for others tests - PrintWriter writer = new PrintWriter(new File("target/alarm-test.log")); - writer.print(""); - writer.close(); - - } - - @Test - public void testAlarm() throws IOException { - - msoAlarmLogger.sendAlarm("test", 0, "detail message"); - msoAlarmLogger.sendAlarm("test2", 1, "detail message2"); - msoAlarmLogger.sendAlarm("test3", 2, "detail message3"); - - FileInputStream inputStream = new FileInputStream("target/alarm-test.log"); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - - String line = reader.readLine(); - String[] splitLine = line.split("\\|"); - assertTrue(splitLine.length==4); - assertTrue("test".equals(splitLine[1])); - assertTrue("0".equals(splitLine[2])); - assertTrue("detail message".equals(splitLine[3])); - - line = reader.readLine(); - splitLine = line.split("\\|"); - assertTrue(splitLine.length==4); - assertTrue("test2".equals(splitLine[1])); - assertTrue("1".equals(splitLine[2])); - assertTrue("detail message2".equals(splitLine[3])); - - line = reader.readLine(); - splitLine = line.split("\\|"); - assertTrue(splitLine.length==4); - assertTrue("test3".equals(splitLine[1])); - assertTrue("2".equals(splitLine[2])); - assertTrue("detail message3".equals(splitLine[3])); - - line = reader.readLine(); - assertNull(line); - reader.close(); - inputStream.close(); - - // Reset the file for others tests - PrintWriter writer = new PrintWriter(new File("target/alarm-test.log")); - writer.print(""); - writer.close(); - - } -} diff --git a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java deleted file mode 100644 index 6ac7002101..0000000000 --- a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java +++ /dev/null @@ -1,331 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.adapter_utils.tests; - -import org.openecomp.mso.entity.MsoRequest; -import org.openecomp.mso.logger.MessageEnum; -import org.openecomp.mso.logger.MsoLogger; -import org.openecomp.mso.logger.MsoLogger.ErrorCode; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.MDC; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.PrintWriter; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; - -/** - * This class implements all test methods of the MsoLogger features. - * - * - */ -public class MsoLoggerTest { - - static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL); - - /** - * This method is called before any test occurs. It creates a fake tree from - * scratch - */ - @BeforeClass - public static final void prepare() { - - } - - @Before - public final void cleanErrorLogFile() throws FileNotFoundException { - URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); - String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) - + "/MSO/Test/errorjboss.server.name_IS_UNDEFINED.log"; - PrintWriter asdcConfigFileWriter = new PrintWriter(logFile); - asdcConfigFileWriter.print(""); - asdcConfigFileWriter.flush(); - asdcConfigFileWriter.close(); - } - - @Before - public final void cleanMetricLogFile() throws FileNotFoundException { - URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); - String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) - + "/MSO/Test/metricsjboss.server.name_IS_UNDEFINED.log"; - PrintWriter asdcConfigFileWriter = new PrintWriter(logFile); - asdcConfigFileWriter.print(""); - asdcConfigFileWriter.flush(); - asdcConfigFileWriter.close(); - } - - @Before - public final void cleanAuditLogFile() throws FileNotFoundException { - URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); - String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) - + "/MSO/Test/auditjbo.server.name_IS_UNDEFINED.log"; - PrintWriter asdcConfigFileWriter = new PrintWriter(logFile); - asdcConfigFileWriter.print(""); - asdcConfigFileWriter.flush(); - asdcConfigFileWriter.close(); - } - - /** - * This method implements a test of getSeverifyLevel method. - */ - @Test - public final void testGetSeverityLevel() { - - try { - String levelInfo = (String) invokePriveMethod("getSeverityLevel", "INFO"); - Assert.assertEquals(levelInfo, "0"); - - String levelWarn = (String) invokePriveMethod("getSeverityLevel", "WARN"); - Assert.assertEquals(levelWarn, "1"); - - String levelERROR = (String) invokePriveMethod("getSeverityLevel", "ERROR"); - Assert.assertEquals(levelERROR, "2"); - - String levelDEBUG = (String) invokePriveMethod("getSeverityLevel", "DEBUG"); - Assert.assertEquals(levelDEBUG, "0"); - - String levelFATAL = (String) invokePriveMethod("getSeverityLevel", "FATAL"); - Assert.assertEquals(levelFATAL, "3"); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - /** - * This method implements a test of getFinalServiceName method. - */ - @Test - public final void testGetFinalServiceName() { - try { - String serviceName1 = (String) invokePriveMethod("getFinalServiceName", "testServiceName1"); - Assert.assertEquals(serviceName1, "testServiceName1"); - - MsoLogger.setServiceName("testServiceName2"); - String serviceName2 = (String) invokePriveMethod("getFinalServiceName", "testServiceName1"); - Assert.assertEquals(serviceName2, "testServiceName1"); - - String msgNull = null; - String serviceName3 = (String) invokePriveMethod("getFinalServiceName", msgNull); - Assert.assertEquals(serviceName3, "testServiceName2"); - - MsoLogger.resetServiceName(); - String serviceName4 = (String) invokePriveMethod("getFinalServiceName", msgNull); - Assert.assertEquals(serviceName4, "invoke0"); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public final void testPrepareMsg() { - try { - String msgNull = null; - MDC.clear(); - invokePrepareMsg("INFO", null, null); - - Assert.assertTrue(MDC.get(MsoLogger.REQUEST_ID).equals("trace-#") - && MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("trace-#") - && MDC.get(MsoLogger.SERVICE_NAME).equals("invoke0") && MDC.get(MsoLogger.TIMER) == null - && MDC.get(MsoLogger.ALERT_SEVERITY).equals("0")); - - MsoLogger.setLoggerParameters("testRemoteIp", "testUser"); - MsoLogger.setLogContext("testReqId", "testSvcId"); - invokePrepareMsg("ERROR", "testServiceName3", null); - Assert.assertTrue(MDC.get(MsoLogger.REQUEST_ID).equals("testReqId") - && MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("testSvcId") - && MDC.get(MsoLogger.SERVICE_NAME).equals("testServiceName3") && MDC.get(MsoLogger.TIMER) == null - && MDC.get(MsoLogger.ALERT_SEVERITY).equals("2")); - - MsoLogger.setServiceName("testServiceName2"); - invokePrepareMsg("WARN", msgNull, msgNull); - Assert.assertTrue(MDC.get(MsoLogger.REQUEST_ID).equals("testReqId") - && MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("testSvcId") - && MDC.get(MsoLogger.SERVICE_NAME).equals("testServiceName2") && MDC.get(MsoLogger.TIMER) == null - && MDC.get(MsoLogger.ALERT_SEVERITY).equals("1")); - - MDC.clear(); - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("reqId2"); - msoRequest.setServiceInstanceId("servId2"); - MsoLogger.setLogContext(msoRequest); - invokePrepareMsg("FATAL", null, "123"); - Assert.assertTrue(MDC.get(MsoLogger.REQUEST_ID).equals("reqId2") - && MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("servId2") - && MDC.get(MsoLogger.TIMER).equals("123") && MDC.get(MsoLogger.ALERT_SEVERITY).equals("3")); - - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - /** - * This method implements a test of log methods - */ - @Test - @Ignore - public final void testLogMethods() { - try { - MDC.clear(); - MsoLogger.setLogContext("reqId2", "servId2"); - MsoLogger.setServiceName("MSO.testServiceName"); - msoLogger.info(MessageEnum.LOGGER_UPDATE_SUC, "testLogger", "INFO", "DEBUG", "target entity", - "target service"); - msoLogger.warn(MessageEnum.GENERAL_WARNING, "warning test", "", "", MsoLogger.ErrorCode.UnknownError, - "warning test"); - msoLogger.error(MessageEnum.GENERAL_EXCEPTION, "target entity", "target service", - MsoLogger.ErrorCode.UnknownError, "error test"); - - // Fetch from the error log - URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); - String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) - + "/MSO/Test/errorjboss.server.name_IS_UNDEFINED.log"; - - Path filePath = new File(logFile).toPath(); - Charset charset = Charset.defaultCharset(); - List stringList = Files.readAllLines(filePath, charset); - String[] stringArray = stringList.toArray(new String[] {}); - int size = stringArray.length; - - Assert.assertTrue(stringArray[size - 3] - .contains("|reqId2|main|MSO.testServiceName||target entity|target service|INFO|null||") - && stringArray[size - 3].contains( - "||MSO-GENERAL-5408I Successfully update Logger: testLogger from level INFO to level DEBUG")); - Assert.assertTrue(stringArray[size - 2] - .contains("|reqId2|main|MSO.testServiceName||||WARN|UnknownError|warning test|") - && stringArray[size - 2].contains("|MSO-GENERAL-5401W WARNING: warning test")); - Assert.assertTrue(stringArray[size - 1].contains( - "|reqId2|main|MSO.testServiceName||target entity|target service|ERROR|UnknownError|error test|") - && stringArray[size - 1].contains("|MSO-GENERAL-9401E Exception encountered")); - - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - /** - * This method implements a test of recordMetricEvent method. - * - * @throws IOException - */ - @Test - @Ignore - public final void testRecordMetricEvent() throws IOException { - MDC.clear(); - MsoLogger.setLogContext("reqId", "servId"); - msoLogger.recordMetricEvent(123456789L, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful", - "VNF", "createVNF", null); - MDC.put(MsoLogger.REMOTE_HOST, "127.0.0.1"); - MDC.put(MsoLogger.PARTNERNAME, "testUser"); - msoLogger.recordMetricEvent(123456789L, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.ServiceNotAvailable, - "Exception", "SDNC", "removeSDNC", "testVNF"); - - // Fetch from the metric log - URL url = this.getClass().getClassLoader().getResource("logback-test.xml"); - String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) - + "/MSO/Test/metricsjboss.server.name_IS_UNDEFINED.log"; - - Path filePath = new File(logFile).toPath(); - Charset charset = Charset.defaultCharset(); - List stringList = Files.readAllLines(filePath, charset); - String[] stringArray = stringList.toArray(new String[] {}); - msoLogger.error(MessageEnum.GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.UnknownError, "test error msg"); - - Assert.assertTrue(stringArray[0] - .contains("|reqId|servId|main||testRecordMetricEvent||VNF|createVNF|COMPLETE|0|Successful|")); - // count the occurance of symbol "|" - Assert.assertTrue((stringArray[0].length() - stringArray[0].replace("|", "").length()) == 28); - Assert.assertTrue(stringArray[1] - .contains("|reqId|servId|main||testRecordMetricEvent|testUser|SDNC|removeSDNC|ERROR|501|Exception|") - && stringArray[1].contains("|127.0.0.1||||testVNF|||||")); - Assert.assertTrue((stringArray[1].length() - stringArray[1].replace("|", "").length()) == 28); - } - - /** - * This method implements a test of testRecordAuditEvent method. - */ - - // User reflection to invoke to avoid change the publicity of the method - private static String invokePrepareMsg(String arg1, String arg2, String arg3) { - Method method; - try { - method = MsoLogger.class.getDeclaredMethod("prepareMsg", String.class, String.class, String.class); - method.setAccessible(true); - return (String) method.invoke(msoLogger, arg1, arg2, arg3); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } - - // User reflection to invoke to avoid change the publicity of the method - private static Object invokePriveMethod(String methodName, String arg) { - Method method; - try { - method = MsoLogger.class.getDeclaredMethod(methodName, String.class); - method.setAccessible(true); - return method.invoke(msoLogger, arg); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } -} diff --git a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryConcurrencyTest.java b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryConcurrencyTest.java deleted file mode 100644 index a814c4ea9c..0000000000 --- a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryConcurrencyTest.java +++ /dev/null @@ -1,174 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.adapter_utils.tests; - - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.FileNotFoundException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -import org.junit.BeforeClass; -import org.junit.Test; - -import org.openecomp.mso.properties.AbstractMsoProperties; -import org.openecomp.mso.properties.MsoJavaProperties; -import org.openecomp.mso.properties.MsoPropertiesException; -import org.openecomp.mso.properties.MsoPropertiesFactory; - -/** - * This class implements test methods of the MsoPropertiesFactory features. - * - * - */ -public class MsoPropertiesFactoryConcurrencyTest { - - public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); - - public static final String MSO_PROP_ID = "TEST_PROP"; - public static final String PATH_MSO_PROP1 = MsoJavaProperties.class.getClassLoader().getResource("mso.properties") - .toString().substring(5); - public static final String PATH_MSO_PROP2 = MsoJavaProperties.class.getClassLoader().getResource("mso2.properties") - .toString().substring(5); - - /** - * This method is called before any test occurs. It creates a fake tree from - * scratch - * - * @throws MsoPropertiesException - */ - @BeforeClass - public static final void prepare() throws MsoPropertiesException { - // it's possible to have it already initialized, as tests are executed in the same JVM - msoPropertiesFactory.removeAllMsoProperties (); - msoPropertiesFactory.initializeMsoProperties(MSO_PROP_ID, PATH_MSO_PROP1); - } - - private Callable taskReload = new Callable() { - @Override - public Integer call() { - try { - if (!msoPropertiesFactory.reloadMsoProperties()) { - return 1; - } - } catch (Exception e) { - e.printStackTrace (); - return 1; - } - return 0; - } - }; - - private Callable taskRead = new Callable() { - @Override - public Integer call() { - try { - MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_PROP_ID); - String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue"); - String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue"); - String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue"); - String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue"); - String property5 = msoProperties.getProperty("does.not.exist", "defaultValue"); - String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue"); - String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue"); - - assertEquals(property1, "MT"); - assertEquals(property2, "http://localhost:5000/v2.0"); - assertEquals(property3, "John"); - assertEquals(property4, "FD205490A48D48475607C36B9AD902BF"); - assertEquals(property5, "defaultValue"); - assertEquals(property6, "1234"); - assertEquals(property7, "true"); - - } catch (MsoPropertiesException e) { - e.printStackTrace (); - return 1; - } - return 0; - } - }; - - private Callable taskReadAll = new Callable() { - @Override - public Integer call() { - try { - List msoPropertiesList = msoPropertiesFactory.getAllMsoProperties(); - String property1 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue"); - String property2 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue"); - String property3 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.msoId", "defaultValue"); - String property4 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue"); - String property5 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("does.not.exist", "defaultValue"); - String property6 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.test", "defaultValue"); - String property7 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.boolean", "defaultValue"); - - assertEquals(property1, "MT"); - assertEquals(property2, "http://localhost:5000/v2.0"); - assertEquals(property3, "John"); - assertEquals(property4, "FD205490A48D48475607C36B9AD902BF"); - assertEquals(property5, "defaultValue"); - assertEquals(property6, "1234"); - assertEquals(property7, "true"); - } catch (Exception e) { - e.printStackTrace (); - return 1; - } - return 0; - } - }; - - @Test - public final void testGetMsoProperties() - throws MsoPropertiesException, InterruptedException, ExecutionException, FileNotFoundException { - - List> list = new ArrayList<>(); - ExecutorService executor = Executors.newFixedThreadPool(20); - - for (int i = 0; i <= 100000; i++) { - - Future futureResult = executor.submit(taskRead); - list.add(futureResult); - - futureResult = executor.submit(taskReload); - list.add(futureResult); - - futureResult = executor.submit(taskReadAll); - list.add(futureResult); - } - executor.shutdown(); - while (!executor.awaitTermination(5, TimeUnit.SECONDS)) { - ; - } - - for (Future result : list) { - assertTrue(result.get().equals(0)); - } - - } - -} diff --git a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryTest.java b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryTest.java deleted file mode 100644 index db58c5a49e..0000000000 --- a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryTest.java +++ /dev/null @@ -1,611 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.adapter_utils.tests; - - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.openecomp.mso.properties.MsoJavaProperties; -import org.openecomp.mso.properties.MsoJsonProperties; -import org.openecomp.mso.properties.MsoPropertiesException; -import org.openecomp.mso.properties.MsoPropertiesFactory; - -import com.fasterxml.jackson.databind.JsonNode; - -/** - * This class implements test methods of the MsoPropertiesFactory features. - * - * - */ -public class MsoPropertiesFactoryTest { - - public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); - - public static final String MSO_JAVA_PROP_ID = "TEST_JAVA_PROP"; - public static final String MSO_JSON_PROP_ID = "TEST_JSON_PROP"; - public static final String PATH_MSO_JAVA_PROP1 = MsoJavaProperties.class.getClassLoader().getResource("mso.properties") - .toString().substring(5); - public static final String PATH_MSO_JAVA_PROP2 = MsoJavaProperties.class.getClassLoader().getResource("mso2.properties") - .toString().substring(5); - public static final String PATH_MSO_JSON_PROP = MsoJavaProperties.class.getClassLoader().getResource("mso.json") - .toString().substring(5); - public static final String PATH_MSO_JSON_PROP2 = MsoJavaProperties.class.getClassLoader().getResource("mso2.json") - .toString().substring(5); - public static final String PATH_MSO_JSON_PROP_BAD = MsoJavaProperties.class.getClassLoader().getResource("mso-bad.json") - .toString().substring(5); - - @BeforeClass - public static final void prepareBeforeAllTests() { - msoPropertiesFactory.removeAllMsoProperties(); - } - /** - * This method is called before any test occurs. It creates a fake tree from - * scratch - * - * @throws MsoPropertiesException - */ - @Before - public final void prepareBeforeEachTest() throws MsoPropertiesException { - - msoPropertiesFactory.initializeMsoProperties(MSO_JAVA_PROP_ID, PATH_MSO_JAVA_PROP1); - msoPropertiesFactory.initializeMsoProperties(MSO_JSON_PROP_ID, PATH_MSO_JSON_PROP); - } - - @After - public final void cleanAfterEachTest() throws MsoPropertiesException { - msoPropertiesFactory.removeAllMsoProperties (); - } - - @Test - public final void testNotRecognizedFile() { - try { - msoPropertiesFactory.initializeMsoProperties("BAD_FILE", "new_file.toto"); - - fail ("MsoPropertiesException should have been raised"); - } catch (MsoPropertiesException ep) { - assertTrue(("Unable to load the MSO properties file because format is not recognized (only .json or .properties): new_file.toto").equals(ep.getMessage())); - } - } - - @Test - public final void testDoubleInit() { - - try { - msoPropertiesFactory.initializeMsoProperties(MSO_JAVA_PROP_ID, PATH_MSO_JAVA_PROP1); - - fail ("MsoPropertiesException should have been raised"); - } catch (MsoPropertiesException ep) { - assertTrue(("The factory contains already an instance of this mso properties: "+PATH_MSO_JAVA_PROP1).equals(ep.getMessage())); - } - - - } - - /** - * This method implements a test for the getMsoJavaProperties method. - * - * @throws MsoPropertiesException - */ - @Test - public final void testGetMsoJavaProperties() throws MsoPropertiesException { - assertNotNull(msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID)); - assertTrue(msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID).size()==8); - - try { - msoPropertiesFactory.getMsoJavaProperties(MSO_JSON_PROP_ID); - - fail ("MsoPropertiesException should have been raised"); - } catch (MsoPropertiesException ep) { - assertTrue(("Mso properties is not JAVA_PROP properties type:" + MSO_JSON_PROP_ID).equals(ep.getMessage())); - } - - try { - msoPropertiesFactory.getMsoJavaProperties("DUMB_PROP"); - - fail ("MsoPropertiesException should have been raised"); - } catch (MsoPropertiesException ep) { - assertTrue(("Mso properties not found in cache:"+"DUMB_PROP").equals(ep.getMessage())); - } - - } - - /** - * This method test the MsoJavaProperties Set, equals and hascode - * @throws MsoPropertiesException - */ - @Test - public final void testSetMsoJavaProperties() throws MsoPropertiesException { - MsoJavaProperties msoPropChanged = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID); - msoPropChanged.setProperty("testos", "testos"); - assertNotNull(msoPropChanged.getProperty("testos", null)); - - // Check no modification occurred on cache one - MsoJavaProperties msoPropCache = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID); - assertNull(msoPropCache.getProperty("testos", null)); - assertFalse(msoPropChanged.hashCode() != msoPropCache.hashCode()); - - assertFalse(msoPropChanged.equals(null)); - assertFalse(msoPropChanged.equals(msoPropCache)); - assertFalse(msoPropChanged.equals(Boolean.TRUE)); - - assertTrue(msoPropChanged.equals(msoPropChanged)); - } - - - /** - * This method implements a test for the testGetMsoJsonProperties method. - * - * @throws MsoPropertiesException - */ - @Test - public final void testGetMsoJsonProperties() throws MsoPropertiesException { - assertNotNull(msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID)); - - try { - msoPropertiesFactory.getMsoJsonProperties(MSO_JAVA_PROP_ID); - - fail ("MsoPropertiesException should have been raised"); - } catch (MsoPropertiesException ep) { - assertTrue(("Mso properties is not JSON_PROP properties type:" + MSO_JAVA_PROP_ID).equals(ep.getMessage())); - } - - try { - msoPropertiesFactory.getMsoJsonProperties("DUMB_PROP"); - - fail ("MsoPropertiesException should have been raised"); - } catch (MsoPropertiesException ep) { - assertTrue(("Mso properties not found in cache:"+"DUMB_PROP").equals(ep.getMessage())); - } - - } - - /** - * This method implements a test for the testGetAllMsoProperties method. - * - * @throws MsoPropertiesException - */ - @Test - public final void testGetAllMsoProperties() throws MsoPropertiesException { - assertNotNull(msoPropertiesFactory.getAllMsoProperties().size()==2); - - } - - /** - * This method implements a test for the testGetAllMsoProperties method. - * - * @throws MsoPropertiesException - */ - @Test - public final void testToString() throws MsoPropertiesException { - String dump = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID).toString(); - assertTrue(dump != null && !dump.isEmpty()); - - dump = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID).toString(); - assertTrue(dump != null && !dump.isEmpty()); - - } - - /** - * This method implements a test for the getProperty of JAVA_PROP type method. - * - * @throws MsoPropertiesException - */ - @Test - public final void testGetProperties() throws MsoPropertiesException { - MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID); - - String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue"); - String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue"); - String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue"); - String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue"); - String property5 = msoProperties.getProperty("does.not.exist", "defaultValue"); - String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue"); - String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue"); - - assertEquals(property1, "MT"); - assertEquals(property2, "http://localhost:5000/v2.0"); - assertEquals(property3, "John"); - assertEquals(property4, "FD205490A48D48475607C36B9AD902BF"); - assertEquals(property5, "defaultValue"); - assertEquals(property6, "1234"); - assertEquals(property7, "true"); - } - - /** - * This method implements a test for the getIntProperty JAVA_RPOP type method. - * - * @throws MsoPropertiesException - */ - @Test - public final void testGetIntProperties() throws MsoPropertiesException { - MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID); - int property1 = msoProperties.getIntProperty("ecomp.mso.cloud.1.test", 345); - int property2 = msoProperties.getIntProperty("ecomp.mso.cloud.1.publicNetId", 345); - int property3 = msoProperties.getIntProperty("does.not.exist", 345); - assertEquals(property1, 1234); - assertEquals(property2, 345); - assertEquals(property3, 345); - } - - /** - * This method implements a test for the getBooleanProperty JAVA_RPOP type method. - * - * @throws MsoPropertiesException - */ - @Test - public final void testGetBooleanProperty() throws MsoPropertiesException { - MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID); - boolean property1 = msoProperties.getBooleanProperty("ecomp.mso.cloud.1.boolean", false); - boolean property2 = msoProperties.getBooleanProperty("ecomp.mso.cloud.1.publicNetId", false); - boolean property3NotThere = msoProperties.getBooleanProperty("ecomp.mso.cloud.1.publicNetIdBad", true); - - assertEquals(property1, true); - assertEquals(property2, false); - assertEquals(property3NotThere, true); - } - - /** - * This method implements a test for the getEncryptedProperty JAVA_RPOP type method. - * - * @throws MsoPropertiesException - */ - @Test - public final void testGetEncryptedProperty() throws MsoPropertiesException { - MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID); - String property1 = msoProperties.getEncryptedProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue", - "aa3871669d893c7fb8abbcda31b88b4f"); - String property2 = msoProperties.getEncryptedProperty("test", "defaultValue", - "aa3871669d893c7fb8abbcda31b88b4f"); - - - String property3Wrong = msoProperties.getEncryptedProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue", - "aa3871669d893c7fb8abbcda31b88b4"); - - - assertEquals(property1, "changeme"); - assertEquals(property2, "defaultValue"); - assertEquals(property3Wrong, "defaultValue"); - } - - /** - * This method implements a test for the getEncryptedProperty JAVA_RPOP type method. - * - * @throws MsoPropertiesException - */ - @Test - public final void testencryptProperty() { - - assertTrue("FD205490A48D48475607C36B9AD902BF" - .contains(msoPropertiesFactory.encryptProperty("changeme", "aa3871669d893c7fb8abbcda31b88b4f").getEntity().toString())); - - - assertTrue("Invalid AES key length: 15 bytes".contains(msoPropertiesFactory.encryptProperty("changeme", "aa3871669d893c7fb8abbcda31b88b4").getEntity().toString())); - - } - - /** - * This method implements a test for the getJSON JSON_RPOP type method. - * - * @throws MsoPropertiesException - */ - @Test - public final void testGetJsonNode() throws MsoPropertiesException { - MsoJsonProperties msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID); - - JsonNode propNode = msoProperties.getJsonRootNode(); - assertNotNull(propNode); - assertFalse(propNode.toString().isEmpty()); - assertTrue(propNode.isContainerNode()); - assertNotNull(propNode.path("asdc-connections").path("asdc-controller1")); - assertNotNull(propNode.path("asdc-connections").path("asdc-controller2")); - - } - - /** - * This method implements a test for the reloadMsoProperties method. - * - * @throws MsoPropertiesException - * - */ - @Test - public final void testReloadJavaMsoProperties() throws MsoPropertiesException { - MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID); - - // Do some additional test on propertiesHaveChanged method - assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, null)); - - // Change path with bad one - try { - msoPropertiesFactory.changeMsoPropertiesFilePath("DO_NOT_EXIST", PATH_MSO_JAVA_PROP2); - - fail ("MsoPropertiesException should have been raised"); - } catch (MsoPropertiesException ep) { - assertTrue(("Mso properties not found in cache:DO_NOT_EXIST").equals(ep.getMessage())); - } - - - // Change path with right one - msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JAVA_PROP_ID, PATH_MSO_JAVA_PROP2); - assertTrue(PATH_MSO_JAVA_PROP2.equals(msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID).getPropertiesFileName())); - - assertTrue(msoPropertiesFactory.reloadMsoProperties()); - assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties)); - // Do a second time as timer value is set to 2 - assertTrue(msoPropertiesFactory.reloadMsoProperties()); - assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties)); - - // Get the new one - msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID); - String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue"); - String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue"); - String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue"); - String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue"); - String property5 = msoProperties.getProperty("does.not.exist", "defaultValue"); - String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue"); - String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue"); - - assertEquals(property1, "MT2"); - assertEquals(property2, "defaultValue"); - assertEquals(property3, "defaultValue"); - assertEquals(property4, "defaultValue"); - assertEquals(property5, "defaultValue"); - assertEquals(property6, "defaultValue"); - assertEquals(property7, "defaultValue"); - - // Additional test on propertiesHaveChanged - msoPropertiesFactory.removeAllMsoProperties(); - - // Do some additional test on propertiesHaveChanged method - try { - msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, null); - - fail ("MsoPropertiesException should have been raised"); - } catch (MsoPropertiesException ep) { - assertTrue(("Mso properties not found in cache:"+MSO_JAVA_PROP_ID).equals(ep.getMessage())); - } - - try { - msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties); - - fail ("MsoPropertiesException should have been raised"); - } catch (MsoPropertiesException ep) { - assertTrue(("Mso properties not found in cache:"+MSO_JAVA_PROP_ID).equals(ep.getMessage())); - } - - } - - /** - * This method implements a test for the reloadMsoProperties method. - * - * @throws MsoPropertiesException - * - */ - @Test - public final void testReloadMoreThanAMinuteMsoProperties() throws MsoPropertiesException { - MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID); - - msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JAVA_PROP_ID, PATH_MSO_JAVA_PROP2); - - // Simulate 2 minutes - msoPropertiesFactory.reloadMsoProperties(); - assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties)); - msoPropertiesFactory.reloadMsoProperties(); - - assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties)); - - // Get the new one - msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID); - String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue"); - String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue"); - String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue"); - String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue"); - String property5 = msoProperties.getProperty("does.not.exist", "defaultValue"); - String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue"); - String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue"); - - assertEquals(property1, "MT2"); - assertEquals(property2, "defaultValue"); - assertEquals(property3, "defaultValue"); - assertEquals(property4, "defaultValue"); - assertEquals(property5, "defaultValue"); - assertEquals(property6, "defaultValue"); - assertEquals(property7, "defaultValue"); - - - } - - /** - * This method implements a test for the reloadMsoProperties method. - * - * @throws MsoPropertiesException - * - */ - @Test - public final void testReloadBadMsoProperties() throws MsoPropertiesException { - MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID); - - msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JAVA_PROP_ID, "file-does-not-exist.properties"); - msoPropertiesFactory.reloadMsoProperties(); - assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties)); - // Reload it a second time as initial timer parameter was set to 2 - msoPropertiesFactory.reloadMsoProperties(); - - assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties)); - - // Get the new one - msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID); - String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue"); - String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue"); - String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue"); - String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue"); - String property5 = msoProperties.getProperty("does.not.exist", "defaultValue"); - String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue"); - String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue"); - - assertEquals(property1, "defaultValue"); - assertEquals(property2, "defaultValue"); - assertEquals(property3, "defaultValue"); - assertEquals(property4, "defaultValue"); - assertEquals(property5, "defaultValue"); - assertEquals(property6, "defaultValue"); - assertEquals(property7, "defaultValue"); - - } - - /** - * This method implements a test for the reloadMsoProperties method. - * - * @throws MsoPropertiesException - * - */ - @Test - public final void testReloadBadMsoJsonProperties() throws MsoPropertiesException { - // Load a bad JSON file - MsoJsonProperties msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID); - - msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JSON_PROP_ID, PATH_MSO_JSON_PROP_BAD); - - msoPropertiesFactory.reloadMsoProperties(); - assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties)); - // Reload it a second time as initial timer parameter was set to 2 - msoPropertiesFactory.reloadMsoProperties(); - - assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties)); - - // Get the new one - msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID); - assertNotNull(msoProperties); - assertNotNull(msoProperties.getJsonRootNode()); - assertTrue(msoProperties.getJsonRootNode().size() == 0); - - } - - @Test - public final void testRemoveMsoProperties() throws MsoPropertiesException { - try { - msoPropertiesFactory.removeMsoProperties("DUMB_PROP"); - - fail ("MsoPropertiesException should have been raised"); - } catch (MsoPropertiesException ep) { - assertTrue(("Mso properties not found in cache:"+"DUMB_PROP").equals(ep.getMessage())); - } - - msoPropertiesFactory.removeMsoProperties(MSO_JAVA_PROP_ID); - - try { - msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID); - - fail ("MsoPropertiesException should have been raised"); - } catch (MsoPropertiesException ep) { - assertTrue(("Mso properties not found in cache:"+MSO_JAVA_PROP_ID).equals(ep.getMessage())); - } - - } - - @Test - public final void testInitializeWithNonExistingPropertiesFile () throws MsoPropertiesException { - try { - msoPropertiesFactory.initializeMsoProperties("NEW_BAD_FILE", "no_file.properties"); - fail ("MsoPropertiesException should have been raised"); - } catch (MsoPropertiesException ep) { - assertTrue(("Unable to load the MSO properties file because it has not been found:no_file.properties").equals(ep.getMessage())); - } - - // empty object should be returned as no config has been loaded, anyway no exception should be raised because the config ID must be loaded in cache - // This is there for automatic reload attempt - assertTrue(msoPropertiesFactory.getMsoJavaProperties("NEW_BAD_FILE").size()==0); - } - - - @Test - public final void testInitializeWithNonExistingJsonFile () throws MsoPropertiesException { - try { - msoPropertiesFactory.initializeMsoProperties("NEW_BAD_FILE", "no_file.json"); - fail ("MsoPropertiesException should have been raised"); - } catch (MsoPropertiesException ep) { - assertTrue(("Unable to load the MSO properties file because it has not been found:no_file.json").equals(ep.getMessage())); - } - - // empty object should be returned as no config has been loaded, anyway no exception should be raised because the config ID must be loaded in cache - // This is there for automatic reload attempt - assertTrue(msoPropertiesFactory.getMsoJsonProperties("NEW_BAD_FILE").getJsonRootNode()!=null); - assertTrue("{}".equals(msoPropertiesFactory.getMsoJsonProperties("NEW_BAD_FILE").getJsonRootNode().toString())); - } - - @Test - public final void testShowProperties() { - assertTrue(msoPropertiesFactory.showProperties().getEntity().toString().contains("/target/test-classes/mso.json(Timer:2mins)")); - assertTrue(msoPropertiesFactory.showProperties().getEntity().toString().contains("asdc-controller1")); - assertTrue(msoPropertiesFactory.showProperties().getEntity().toString().contains("/target/test-classes/mso.properties(Timer:2mins):")); - assertTrue(msoPropertiesFactory.showProperties().getEntity().toString().contains("ecomp.mso.cloud.1.keystoneUrl")); - - } - - @Test - public final void testGetEncryptedPropertyJson() throws MsoPropertiesException { - MsoJsonProperties msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID); - assertTrue("ThePassword".equals(msoProperties.getEncryptedProperty(msoProperties.getJsonRootNode().get("asdc-connections").get("asdc-controller1").get("asdcPassword"),"defautlvalue","566B754875657232314F5548556D3665"))); - - assertTrue("defautlvalue".equals(msoProperties.getEncryptedProperty(msoProperties.getJsonRootNode().get("asdc-connections").get("asdc-controller1").get("asdcPassword"),"defautlvalue","566B754875657232314F5548556D366"))); - - - } - - @Test - public final void testHashcodeAndEqualsMsoJsonProperties() throws MsoPropertiesException { - - MsoJsonProperties msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID); - - msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JSON_PROP_ID, PATH_MSO_JSON_PROP2); - - msoPropertiesFactory.reloadMsoProperties(); - assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties)); - // Reload it a second time as initial timer parameter was set to 2 - msoPropertiesFactory.reloadMsoProperties(); - assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties)); - - // Get the new one - MsoJsonProperties msoProperties2 = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID); - assertFalse(msoProperties.hashCode()==msoProperties2.hashCode()); - - assertFalse(msoProperties.equals(msoProperties2)); - assertTrue(msoProperties.equals(msoProperties)); - assertFalse(msoProperties.equals(null)); - assertFalse(msoProperties.toString().isEmpty()); - - // Test a reload with timer set to 1 in PATH_MSO_JSON_PROP2 - msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JSON_PROP_ID, PATH_MSO_JSON_PROP); - - msoPropertiesFactory.reloadMsoProperties(); - assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties2)); - - } - -} diff --git a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertyInitializerTest.java b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertyInitializerTest.java deleted file mode 100644 index 419a82b8a4..0000000000 --- a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertyInitializerTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.adapter_utils.tests; - - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; - -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.mockito.Mockito; - -import org.openecomp.mso.properties.MsoJavaProperties; -import org.openecomp.mso.properties.MsoPropertiesException; -import org.openecomp.mso.properties.MsoPropertiesFactory; -import org.openecomp.mso.properties.MsoPropertyInitializer; - -public class MsoPropertyInitializerTest { - - public static final String ASDC_PROP = MsoJavaProperties.class.getClassLoader().getResource("mso.json").toString().substring(5); - public static ServletContextEvent servletContextEvent = Mockito.mock(ServletContextEvent.class); - public static ServletContext servletContext = Mockito.mock(ServletContext.class); - public MsoPropertyInitializer msoPropInitializer = new MsoPropertyInitializer(); - - @BeforeClass - public static final void prepareBeforeClass() throws MsoPropertiesException { - - Mockito.when(servletContextEvent.getServletContext()).thenReturn(servletContext); - } - - @Before - public final void preparebeforeEachTest() throws MsoPropertiesException { - MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); - msoPropertiesFactory.removeAllMsoProperties(); - - } - - @Test - public void testContextInitialized() throws MsoPropertiesException { - Mockito.when(servletContext.getInitParameter("mso.configuration")).thenReturn("MSO_PROP_ASDC="+ASDC_PROP); - msoPropInitializer.contextInitialized(servletContextEvent); - - MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); - assertNotNull(msoPropertiesFactory.getMsoJsonProperties("MSO_PROP_ASDC")); - assertFalse("{}".equals(msoPropertiesFactory.getMsoJsonProperties("MSO_PROP_ASDC").getJsonRootNode().toString())); - assertTrue(msoPropertiesFactory.getMsoJsonProperties("MSO_PROP_ASDC").getJsonRootNode().get("asdc-connections")!= null); - } - - @Test - public void testContextInitializedFailure() throws MsoPropertiesException { - Mockito.when(servletContext.getInitParameter("mso.configuration")).thenReturn("MSO_PROP_ASDC="+"Does_not_exist.json"); - msoPropInitializer.contextInitialized(servletContextEvent); - - // No exception should be raised, log instead - MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); - - assertTrue("{}".equals(msoPropertiesFactory.getMsoJsonProperties("MSO_PROP_ASDC").getJsonRootNode().toString())); - assertTrue(msoPropertiesFactory.getMsoJsonProperties("MSO_PROP_ASDC").getJsonRootNode().get("asdc-connections")== null); - - - - } - -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/AAIConfigurationTest.java b/common/src/test/java/org/openecomp/mso/client/aai/AAIConfigurationTest.java deleted file mode 100644 index da63b27efb..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/AAIConfigurationTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.aai; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.assertEquals; - -import java.util.UUID; - -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.openecomp.mso.client.aai.entities.uri.AAIUri; -import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory; -import org.openecomp.mso.serviceinstancebeans.ModelInfo; -import org.openecomp.mso.serviceinstancebeans.RequestDetails; - -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class AAIConfigurationTest { - - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8443)); - - @Ignore - @Test - public void verifyCreate() { - AAIConfigurationClient aaiConfiguration = new AAIConfigurationClient(); - ModelInfo modelInfo = new ModelInfo(); - modelInfo.setModelInvariantId("testInvariantID"); - modelInfo.setModelVersionId("testVersionID"); - modelInfo.setModelCustomizationId("testCustomizationID"); - RequestDetails requestDetails = new RequestDetails(); - requestDetails.setModelInfo(modelInfo); - String configurationType = "test"; - String configurationSubType = "test"; - aaiConfiguration.createConfiguration(requestDetails, UUID.randomUUID().toString(), configurationType, configurationSubType); - } - - @Test - public void verifyNotExists() { - AAIUri path = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, "test2"); - wireMockRule.stubFor(get( - urlPathEqualTo("/aai/v11" + path.build())) - .willReturn( - aResponse() - .withHeader("Content-Type", "text/plain") - .withBody("hello") - .withStatus(404))); - AAIConfigurationClient aaiConfiguration = new AAIConfigurationClient(); - boolean result = aaiConfiguration.configurationExists("test2"); - assertEquals("path not found", false, result); - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/AAIExceptionMapperTest.java b/common/src/test/java/org/openecomp/mso/client/aai/AAIExceptionMapperTest.java deleted file mode 100644 index 625e281792..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/AAIExceptionMapperTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.aai; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.openecomp.mso.client.aai.entities.AAIError; - -public class AAIExceptionMapperTest { - - @Mock private AAIError errorObj; - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - } - @Test - public void nestedReplace() { - String error = "Error %1 on %2"; - List list = Arrays.asList("PUT", "hello %1"); - AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj); - String result = formatter.fillInTemplate(error, list); - assertEquals("equal", "Error PUT on hello PUT", result); - - } - - @Test - public void noReplace() { - String error = "Error"; - List list = new ArrayList<>(); - AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj); - String result = formatter.fillInTemplate(error, list); - assertEquals("equal", "Error", result); - - } - -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/AAIObjectTypeTest.java b/common/src/test/java/org/openecomp/mso/client/aai/AAIObjectTypeTest.java deleted file mode 100644 index c8f6299d81..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/AAIObjectTypeTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.aai; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class AAIObjectTypeTest { - - @Test - public void verifyDefaultCase() { - assertEquals("default removed for tenant", "tenant", AAIObjectType.DEFAULT_TENANT.typeName()); - assertEquals("default removed for cloud-region", "cloud-region", AAIObjectType.DEFAULT_CLOUD_REGION.typeName()); - } - - @Test - public void verifyRegularCase() { - assertEquals("default removed for tenant", "allotted-resource", AAIObjectType.ALLOTTED_RESOURCE.typeName()); - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/AAIPServerTest.java b/common/src/test/java/org/openecomp/mso/client/aai/AAIPServerTest.java deleted file mode 100644 index b6b01b384a..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/AAIPServerTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.aai; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.security.NoSuchAlgorithmException; -import java.util.List; -import java.util.UUID; - -import org.junit.Ignore; -import org.junit.Test; -import org.onap.aai.domain.yang.Pserver; - -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -public class AAIPServerTest { - - @Test - public void pserverTest() throws JsonParseException, JsonMappingException, IOException, NoSuchAlgorithmException { - AAIRestClientImpl client = new AAIRestClientImpl(); - String json = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/aai/pserver.json"))); - List list = client.getListOfPservers(json); - - assertEquals("", list.get(0).getHostname(), "test"); - } - - @Test - @Ignore // IGNORED FOR 1710 MERGE TO ONAP - public void pserverActualTest() throws JsonParseException, JsonMappingException, IOException, NoSuchAlgorithmException { - AAIRestClientImpl client = new AAIRestClientImpl(); - List list = client.getPhysicalServerByVnfId("d946afed-8ebe-4c5d-9665-54fcc043b8e7", UUID.randomUUID().toString()); - assertEquals("", list.size(), 0); - } - -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/AAIResourcesClientTest.java b/common/src/test/java/org/openecomp/mso/client/aai/AAIResourcesClientTest.java deleted file mode 100644 index c7cc549130..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/AAIResourcesClientTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.aai; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.delete; -import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.put; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.assertEquals; - -import org.junit.Rule; -import org.junit.Test; -import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri; -import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory; - -import com.github.tomakehurst.wiremock.junit.WireMockRule; -public class AAIResourcesClientTest { - - - - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8443)); - - @Test - public void verifyNotExists() { - AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test"); - wireMockRule.stubFor(get( - urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString())) - .willReturn( - aResponse() - .withHeader("Content-Type", "text/plain") - .withBody("hello") - .withStatus(404))); - AAIResourcesClient client = new AAIResourcesClient(); - boolean result = client.exists(path); - assertEquals("path not found", false, result); - } - - @Test - public void verifyDelete() { - AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2"); - wireMockRule.stubFor(get( - urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString())) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile("aai/resources/mockObject.json") - .withStatus(200))); - wireMockRule.stubFor(delete( - urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString())) - .withQueryParam("resource-version", equalTo("1234")) - .willReturn( - aResponse() - .withStatus(204))); - AAIResourcesClient client = new AAIResourcesClient(); - client.delete(path); - } - - @Test - public void verifyBasicAuth() { - AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3"); - wireMockRule.stubFor(get( - urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString())) - .withHeader("Authorization", equalTo("Basic TVNPOk1TTw==")) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile("aai/resources/mockObject.json") - .withStatus(200))); - AAIResourcesClient client = new AAIResourcesClient(); - client.get(path); - } - - @Test - public void verifyConnect() { - AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2"); - AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3"); - wireMockRule.stubFor(put( - urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString() + "/relationship-list/relationship")) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withStatus(200))); - - AAIResourceUri pathClone = path.clone(); - AAIResourcesClient client = new AAIResourcesClient(); - client.connect(path, path2); - assertEquals("uri not modified", pathClone.build().toString(), path.build().toString()); - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/AAITransactionalClientTest.java b/common/src/test/java/org/openecomp/mso/client/aai/AAITransactionalClientTest.java deleted file mode 100644 index 1abb940f6e..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/AAITransactionalClientTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.aai; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Map; -import java.util.Optional; - -import org.junit.Test; -import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri; -import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; - -public class AAITransactionalClientTest { - - - private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/bulkprocess/"; - - @Test - public void run() throws IOException { - - - AAIResourcesClient client = new AAIResourcesClient(); - AAIResourceUri uriA = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1"); - AAIResourceUri uriB = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test2"); - AAIResourceUri uriC = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3"); - AAIResourceUri uriD = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test4"); - AAIResourceUri uriE = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test5"); - AAIResourceUri uriF = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test6"); - - AAIResourceUri uriAClone = uriA.clone(); - AAITransactionalClient transactions = client - .beginTransaction().connect(uriA, uriB).connect(uriC, uriD) - .beginNewTransaction().connect(uriE, uriF); - ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper(); - mapper.enable(SerializationFeature.INDENT_OUTPUT); - String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions()); - Map map1 = mapper.readValue(serializedTransactions, new TypeReference>(){}); - Map map2 = mapper.readValue(getJson("test-request.json"), new TypeReference>(){}); - assertEquals("payloads are equal", map2, map1); - assertEquals("uri not manipulated", uriAClone.build().toString(), uriA.build().toString()); - } - - @Test - public void verifyResponse() throws IOException { - AAIResourcesClient client = new AAIResourcesClient(); - AAITransactionalClient transactions = client - .beginTransaction(); - assertEquals("success status", Optional.empty(), transactions.locateErrorMessages(getJson("response-success.json"))); - assertEquals(transactions.locateErrorMessages(getJson("response-failure.json")).get(), "another error message\nmy great error"); - - - } - - private String getJson(String filename) throws IOException { - return new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + filename))); - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/AAIURITest.java b/common/src/test/java/org/openecomp/mso/client/aai/AAIURITest.java deleted file mode 100644 index 366c587b11..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/AAIURITest.java +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.aai; - -import static org.junit.Assert.assertEquals; - -import javax.ws.rs.core.UriBuilder; - -import org.junit.Test; -import org.openecomp.mso.client.aai.entities.uri.AAIUri; -import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory; - -public class AAIURITest { - - - - - @Test - public void verifyTemplateReplacement() { - final String id = "test1"; - AAIUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, id); - String manualReplace = AAIObjectType.CONFIGURATION.toString().replaceAll("\\{configuration-id\\}", id); - assertEquals("uri template replaced", aaiUri.build(), UriBuilder.fromPath(manualReplace).build()); - - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/AAIUpdatorImplTest.java b/common/src/test/java/org/openecomp/mso/client/aai/AAIUpdatorImplTest.java deleted file mode 100644 index 86adb5f458..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/AAIUpdatorImplTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.aai; - -import org.junit.Test; - -public class AAIUpdatorImplTest { - - AAIUpdatorImpl test = new AAIUpdatorImpl(); - - protected AAIRestClientI client; - - @Test - public void getClientTest() throws Exception { - test.getClient(); - } - - @Test - public void setClientTest() throws Exception { - test.setClient(client); - } - - - @Test(expected = NullPointerException.class) - public void updateVnfToLockedTest() throws Exception { - test.updateVnfToLocked("vnfId","uuId"); - } - - - @Test(expected = NullPointerException.class) - public void updateVnfToUnLockedTest() throws Exception { - test.updateVnfToUnLocked("vnfId","uuId"); - } - -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/AAIValidatorTest.java b/common/src/test/java/org/openecomp/mso/client/aai/AAIValidatorTest.java deleted file mode 100644 index 12034e0eea..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/AAIValidatorTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.aai; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.aai.domain.yang.GenericVnf; -import org.onap.aai.domain.yang.Pserver; - -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; - -@RunWith(MockitoJUnitRunner.class) -public class AAIValidatorTest { - - @Mock - protected AAIRestClientI client; - String vnfName = "testVnf"; - String uuid = "UUID"; - AAIValidatorImpl validator; - - @Before - public void init(){ - validator = new AAIValidatorImpl(); - validator.setClient(client); - } - - public List getPservers(boolean locked){ - Pserver pserver = new Pserver(); - pserver.setInMaint(locked); - List pservers = new ArrayList(); - pservers.add(pserver); - return pservers; - } - - public GenericVnf createGenericVnfs(boolean locked){ - GenericVnf genericVnf = new GenericVnf(); - genericVnf.setInMaint(locked); - return genericVnf; - } - - @Test - public void test_IsPhysicalServerLocked_True() throws IOException{ - when(client.getPhysicalServerByVnfId(vnfName,uuid)).thenReturn(getPservers(true)); - boolean locked = validator.isPhysicalServerLocked(vnfName, uuid); - assertEquals(true, locked); - } - - @Test - public void test_IsPhysicalServerLocked_False() throws JsonParseException, JsonMappingException, UnsupportedEncodingException, IOException { - when(client.getPhysicalServerByVnfId(vnfName,uuid)).thenReturn(getPservers(false)); - boolean locked = validator.isPhysicalServerLocked(vnfName, uuid); - assertEquals(false, locked); - } - - @Test - public void test_IsVNFLocked_False() throws Exception{ - when(client.getVnfByName(vnfName,uuid)).thenReturn(createGenericVnfs(false)); - boolean locked = validator.isVNFLocked(vnfName, uuid); - assertEquals(false, locked); - } - - @Test - public void test_IsVNFLocked_True() throws Exception{ - when(client.getVnfByName(vnfName,uuid)).thenReturn(createGenericVnfs(true)); - boolean locked = validator.isVNFLocked(vnfName, uuid); - assertEquals(true,locked ); - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/entities/RelationshipsTest.java b/common/src/test/java/org/openecomp/mso/client/aai/entities/RelationshipsTest.java deleted file mode 100644 index b2c1f9ed64..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/entities/RelationshipsTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.aai.entities; - -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.List; - -import org.junit.Test; -import org.openecomp.mso.client.aai.AAIObjectType; -import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri; -import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory; - -public class RelationshipsTest { - - private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/resources/"; - - @Test - public void run() throws IOException { - final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "e2e-complex.json"))); - - AAIResultWrapper wrapper = new AAIResultWrapper(content); - Relationships relationships = wrapper.getRelationships().get(); - - List test = relationships.getRelatedAAIUris(AAIObjectType.VCE); - - System.out.println(test.get(0).build()); - List uris = Arrays.asList( - AAIUriFactory.createResourceUri(AAIObjectType.VCE, "a9fec18e-1ea3-40e4-a6c0-a89b3de07053"), - AAIUriFactory.createResourceUri(AAIObjectType.VCE, "8ae1e5f8-61f1-4c71-913a-b40cc4593cb9"), - AAIUriFactory.createResourceUri(AAIObjectType.VCE, "a2935fa9-b743-49f4-9813-a127f13c4e93"), - AAIUriFactory.createResourceUri(AAIObjectType.VCE, "c7fe7698-8063-4e26-8bd3-ca3edde0b0d4")); - - - assertTrue(uris.containsAll(test) && test.containsAll(uris)); - - } - -} \ No newline at end of file diff --git a/common/src/test/java/org/openecomp/mso/client/aai/entities/uri/AAIUriFactoryTest.java b/common/src/test/java/org/openecomp/mso/client/aai/entities/uri/AAIUriFactoryTest.java deleted file mode 100644 index a62d4b89c6..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/entities/uri/AAIUriFactoryTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.aai.entities.uri; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.openecomp.mso.client.aai.AAIObjectType; - -public class AAIUriFactoryTest { - - - - @Test - public void automaticallyEncodeUriTemplateValue() { - - AAIUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)"); - - String expected = "/network/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29"; - assertEquals(expected, uri.build().toString()); - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/entities/uri/ServiceInstanceUriTest.java b/common/src/test/java/org/openecomp/mso/client/aai/entities/uri/ServiceInstanceUriTest.java deleted file mode 100644 index 12ca0a2709..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/entities/uri/ServiceInstanceUriTest.java +++ /dev/null @@ -1,194 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.aai.entities.uri; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.collection.IsIterableContainingInOrder.contains; -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -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 static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMock.put; -import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static com.github.tomakehurst.wiremock.client.WireMock.containing; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; - - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Optional; - -import javax.ws.rs.BadRequestException; -import javax.ws.rs.core.UriBuilder; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Matchers; -import org.openecomp.mso.client.aai.AAIObjectType; -import org.openecomp.mso.client.aai.AAIQueryClient; -import org.openecomp.mso.client.aai.Format; -import org.openecomp.mso.client.aai.entities.CustomQuery; -import org.openecomp.mso.client.aai.exceptions.AAIPayloadException; -import org.openecomp.mso.client.aai.exceptions.AAIUriComputationException; -import org.openecomp.mso.client.aai.exceptions.AAIUriNotFoundException; - -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class ServiceInstanceUriTest { - - private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/resources/"; - - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8443)); - - @Rule - public final ExpectedException exception = ExpectedException.none(); - - @Test - public void found() throws IOException { - final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "service-instance-pathed-query.json"))); - - ServiceInstanceUri instance = new ServiceInstanceUri("key3"); - final Optional result = instance.extractRelatedLink(content); - final String expected = "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3"; - assertEquals("result is equal", expected, result.get()); - - } - - @Test - public void oneKey() throws IOException, URISyntaxException, AAIUriNotFoundException, AAIPayloadException { - - ServiceInstanceUri instance = new ServiceInstanceUri("key1"); - ServiceInstanceUri spy = spy(instance); - doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3").when(spy).getSerivceInstance(any(Object.class)); - - final URI result = spy.build(); - final URI expected = UriBuilder.fromPath("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3").build(); - assertEquals("result is equal", expected, result); - - } - - @Test - public void oneKeyQueryParams() throws IOException, URISyntaxException, AAIUriNotFoundException, AAIPayloadException { - - ServiceInstanceUri instance = new ServiceInstanceUri("key1"); - ServiceInstanceUri spy = spy(instance); - doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3").when(spy).getSerivceInstance(any(Object.class)); - - final URI result = spy.resourceVersion("1234").build(); - final URI expected = UriBuilder.fromUri("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3?resource-version=1234").build(); - assertEquals("result is equal", expected, result); - - } - - @Test - public void oneKeyEncoded() throws IOException, URISyntaxException, AAIUriNotFoundException, AAIPayloadException { - - ServiceInstanceUri instance = new ServiceInstanceUri("key1"); - ServiceInstanceUri spy = spy(instance); - doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%20space").when(spy).getSerivceInstance(any(Object.class)); - - final URI result = spy.build(); - final URI expected = UriBuilder.fromUri("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%20space").build(); - assertEquals("result is equal", expected, result); - - } - - @Test - public void oneKeyGetKeys() throws IOException, URISyntaxException, AAIUriNotFoundException, AAIPayloadException { - - ServiceInstanceUri instance = new ServiceInstanceUri("key1"); - ServiceInstanceUri spy = spy(instance); - doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%28space").when(spy).getSerivceInstance(any(Object.class)); - - assertThat(spy.getURIKeys().values(), contains("key1", "key2", "key3(space")); - - } - @Test - public void oneKeyClone() throws AAIUriNotFoundException, AAIPayloadException { - ServiceInstanceUri instance = new ServiceInstanceUri("key1"); - ServiceInstanceUri spy = spy(instance); - String uri = "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3"; - doReturn(uri).when(spy).getSerivceInstance(any(Object.class)); - doReturn(Optional.of(uri)).when(spy).getCachedValue(); - final URI result = spy.resourceVersion("1234").clone().build(); - final URI expected = UriBuilder.fromUri("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3?resource-version=1234").build(); - assertEquals("result is equal", expected, result); - } - - @Test - public void threeKey() throws IOException { - - ServiceInstanceUri instance = new ServiceInstanceUri("key1", "key2", "key3"); - final URI result = instance.build(); - final URI expected = UriBuilder.fromPath("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3").build(); - assertEquals("result is equal", expected, result); - - } - - @Test - public void notfound() throws IOException, AAIUriNotFoundException, AAIPayloadException { - final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "empty-query-result.json"))); - - ServiceInstanceUri instance = new ServiceInstanceUri("key3"); - ServiceInstanceUri spy = spy(instance); - AAIQueryClient mockQueryClient = mock(AAIQueryClient.class); - when(mockQueryClient.query(any(Format.class), any(CustomQuery.class))).thenReturn(content); - when(spy.getQueryClient()).thenReturn(mockQueryClient); - exception.expect(AAIUriComputationException.class); - spy.build(); - - } - - @Test - public void cloneTest() { - ServiceInstanceUri instance = new ServiceInstanceUri("key1", "key2", "key3"); - final URI result = instance.build(); - final URI result2 = instance.clone().queryParam("something", "new").build(); - assertEquals("uris are not equal", false, result.toString().equals(result2.toString())); - - } - - @Test - public void noVertexFound() throws AAIUriNotFoundException, AAIPayloadException { - ServiceInstanceUri instance = new ServiceInstanceUri("key3"); - ServiceInstanceUri spy = spy(instance); - stubFor(put(urlMatching("/aai/v[0-9]+/query.*")) - .withRequestBody(containing("key3")) - .willReturn(aResponse() - .withStatus(400) - .withHeader("Content-Type", "application/json") - .withBodyFile(""))); - exception.expect(AAIUriComputationException.class); - exception.expectMessage(containsString("NotFoundException")); - spy.build(); - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/entities/uri/SimpleUriFromUriTest.java b/common/src/test/java/org/openecomp/mso/client/aai/entities/uri/SimpleUriFromUriTest.java deleted file mode 100644 index 6e3ab64108..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/entities/uri/SimpleUriFromUriTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.aai.entities.uri; - -import static org.junit.Assert.assertEquals; - -import javax.ws.rs.core.UriBuilder; - -import org.junit.Test; -import org.openecomp.mso.client.aai.AAIObjectType; - -public class SimpleUriFromUriTest { - - - - @Test - public void removeHost() { - - AAIUri uri = new SimpleUri(AAIObjectType.UNKNOWN, UriBuilder.fromUri("https://aai-conexus-e2e.test.att.com:8443/aai/v9/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053").build()); - - assertEquals("root and version removed", "/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053", uri.build().toString()); - - } - @Test - public void noChange() { - - AAIUri uri = new SimpleUri(AAIObjectType.UNKNOWN, UriBuilder.fromUri("/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053").build()); - - assertEquals("no change", "/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053", uri.build().toString()); - - } - - @Test - public void encodingPreserved() { - - AAIUri uri = new SimpleUri(AAIObjectType.UNKNOWN, UriBuilder.fromUri("/network/vces/vce/a9f%20%20ec18e-1ea3-40e4-a6c0-a89b3de07053").build()); - - assertEquals("encoding preserved", "/network/vces/vce/a9f%20%20ec18e-1ea3-40e4-a6c0-a89b3de07053", uri.build().toString()); - - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/entities/uri/SimpleUriTest.java b/common/src/test/java/org/openecomp/mso/client/aai/entities/uri/SimpleUriTest.java deleted file mode 100644 index f4fe216cd2..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/entities/uri/SimpleUriTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.aai.entities.uri; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.collection.IsIterableContainingInOrder.contains; -import static org.junit.Assert.assertEquals; - -import java.util.Map; - -import org.junit.Test; -import org.openecomp.mso.client.aai.AAIObjectPlurals; -import org.openecomp.mso.client.aai.AAIObjectType; - -public class SimpleUriTest { - - - - @Test - public void relatedToTestPlural() { - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1"); - uri.relatedTo(AAIObjectPlurals.PSERVER); - String uriOutput = uri.build().toString(); - assertEquals(true, uriOutput.contains("related-to")); - } - - @Test - public void relatedToTestSingular() { - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1"); - uri.relatedTo(AAIObjectType.PSERVER, "test2"); - String uriOutput = uri.build().toString(); - assertEquals(true, uriOutput.contains("related-to")); - } - - @Test - public void cloneTest() { - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1"); - AAIResourceUri cloned = uri.clone(); - Map keys = cloned.getURIKeys(); - assertThat(keys.values(), contains("test1")); - } - - @Test - public void getKeysTest() { - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, "cloud1", "cloud2", "tenant1", "vserver1"); - Map keys = uri.getURIKeys(); - System.out.println(keys); - System.out.println(uri.build()); - assertEquals("vserver1", keys.get("vserver-id")); - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/entities/uri/parsers/UriParserSpringImplTest.java b/common/src/test/java/org/openecomp/mso/client/aai/entities/uri/parsers/UriParserSpringImplTest.java deleted file mode 100644 index e8d98718a4..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/entities/uri/parsers/UriParserSpringImplTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.aai.entities.uri.parsers; - -import static org.junit.Assert.assertEquals; - -import java.util.Map; - -import org.junit.Test; -import org.openecomp.mso.client.aai.AAIObjectType; - -public class UriParserSpringImplTest { - - - - - @Test - public void reverseTemplate() { - final UriParser parser = new UriParserSpringImpl(AAIObjectType.SERVICE_INSTANCE.toString()); - final String uri = "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3"; - - Map result = parser.parse(uri); - - assertEquals("found customer-id", "key1", result.get("global-customer-id")); - assertEquals("found service-type", "key2", result.get("service-type")); - assertEquals("found service-instance-id", "key3", result.get("service-instance-id")); - - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/exceptions/AAIPayloadExceptionTest.java b/common/src/test/java/org/openecomp/mso/client/aai/exceptions/AAIPayloadExceptionTest.java deleted file mode 100644 index 3895230ed4..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/exceptions/AAIPayloadExceptionTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.aai.exceptions; - -import org.junit.Test; - -public class AAIPayloadExceptionTest { - - Throwable t = new Throwable(); - - @Test - public void callConstructorTest() throws Exception { - - AAIPayloadException test1 = new AAIPayloadException("testing"); - - AAIPayloadException test2 = new AAIPayloadException("testing", t); - - AAIPayloadException test3 = new AAIPayloadException(t); - } - -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/objects/AAIOperationalEnvironmentTest.java b/common/src/test/java/org/openecomp/mso/client/aai/objects/AAIOperationalEnvironmentTest.java deleted file mode 100644 index f512de848c..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/objects/AAIOperationalEnvironmentTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : SO -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= -*/ -package org.openecomp.mso.client.aai.objects; - -import static org.junit.Assert.*; - -import org.junit.Test; - -public class AAIOperationalEnvironmentTest { - - AAIOperationalEnvironment aaiOE =new AAIOperationalEnvironment(); - - @Test - public void test() { - aaiOE.setOperationalEnvironmentId("operationalEnvironmentId"); - aaiOE.setOperationalEnvironmentName("operationalEnvironmentName"); - aaiOE.setOperationalEnvironmentStatus("operationalEnvironmentStatus"); - aaiOE.setOperationalEnvironmentType("operationalEnvironmentType"); - aaiOE.setResourceVersion("resourceVersion"); - aaiOE.setTenantContext("tenantContext"); - aaiOE.setWorkloadContext("workloadContext"); - assertEquals(aaiOE.getOperationalEnvironmentId(),"operationalEnvironmentId"); - assertEquals(aaiOE.getOperationalEnvironmentName(),"operationalEnvironmentName"); - assertEquals(aaiOE.getOperationalEnvironmentStatus(),"operationalEnvironmentStatus"); - assertEquals(aaiOE.getOperationalEnvironmentType(),"operationalEnvironmentType"); - assertEquals(aaiOE.getResourceVersion(),"resourceVersion"); - assertEquals(aaiOE.getTenantContext(),"tenantContext"); - assertEquals(aaiOE.getWorkloadContext(),"workloadContext"); - aaiOE.withOperationalEnvironmentId("operationalEnvironmentId"); - aaiOE.withOperationalEnvironmentName("operationalEnvironmentName"); - aaiOE.withOperationalEnvironmentStatus("operationalEnvironmentStatus"); - aaiOE.withOperationalEnvironmentType("operationalEnvironmentType"); - aaiOE.withResourceVersion("resourceVersion"); - aaiOE.withTenantContext("tenantContext"); - aaiOE.withWorkloadContext("workloadContext"); - } - -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/objects/AAIOwningEntityTest.java b/common/src/test/java/org/openecomp/mso/client/aai/objects/AAIOwningEntityTest.java deleted file mode 100644 index bc2ae41dd6..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/objects/AAIOwningEntityTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : SO -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= -*/ -package org.openecomp.mso.client.aai.objects; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.openecomp.mso.client.aai.AAIObjectType; -import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri; -import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory; - -public class AAIOwningEntityTest { - AAIOwningEntity aaiOE= new AAIOwningEntity(); - @Test - public void test() { - aaiOE.setOwningEntityId("OwningEntityId"); - aaiOE.setOwningEntityName("OwningEntityName"); - assertEquals(aaiOE.getOwningEntityId(), "OwningEntityId"); - assertEquals(aaiOE.getOwningEntityName(), "OwningEntityName"); - aaiOE.withOwningEntity("OwningEntityId1", "OwningEntityName1"); - assert(aaiOE.getUri()!=null); - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/objects/AAIProjectTest.java b/common/src/test/java/org/openecomp/mso/client/aai/objects/AAIProjectTest.java deleted file mode 100644 index 872b17a759..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/objects/AAIProjectTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : SO -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= -*/ -package org.openecomp.mso.client.aai.objects; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.openecomp.mso.client.aai.AAIObjectType; -import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri; -import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory; - -public class AAIProjectTest { - - - @Test - public void test() { - AAIProject aaiP =new AAIProject(); - aaiP.setProjectName("projectName"); - assertEquals(aaiP.getProjectName(),"projectName"); - aaiP.withProjectName("projectName"); - assert(aaiP.getUri()!=null); - - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/aai/objects/AAIServiceInstanceTest.java b/common/src/test/java/org/openecomp/mso/client/aai/objects/AAIServiceInstanceTest.java deleted file mode 100644 index 692e3bba0b..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/aai/objects/AAIServiceInstanceTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : SO -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* ============LICENSE_END========================================================= -*/ -package org.openecomp.mso.client.aai.objects; - -import static org.junit.Assert.*; - -import org.junit.Test; - -public class AAIServiceInstanceTest { - - @Test - public void test() { - AAIServiceInstance aaiSI= new AAIServiceInstance(); - aaiSI.setEnvironmentContext("environmentContext"); - aaiSI.setModelInvariantUuid("modelInvariantUuid"); - aaiSI.setModelUuid("modelUuid"); - aaiSI.setoStatus("oStatus"); - aaiSI.setServiceInstanceId("serviceInstanceId"); - aaiSI.setServiceInstanceName("serviceInstanceName"); - aaiSI.setServiceRole("serviceRole"); - aaiSI.setServiceType("serviceType"); - aaiSI.setWorkloadContext("workloadContext"); - assertEquals(aaiSI.getEnvironmentContext(), "environmentContext"); - assertEquals(aaiSI.getModelInvariantUuid(), "modelInvariantUuid"); - assertEquals(aaiSI.getModelUuid(), "modelUuid"); - assertEquals(aaiSI.getoStatus(), "oStatus"); - assertEquals(aaiSI.getServiceInstanceId(), "serviceInstanceId"); - assertEquals(aaiSI.getServiceInstanceName(), "serviceInstanceName"); - assertEquals(aaiSI.getServiceRole(), "serviceRole"); - assertEquals(aaiSI.getServiceType(), "serviceType"); - assertEquals(aaiSI.getWorkloadContext(), "workloadContext"); - aaiSI.withServiceInstance("serviceInstanceId"); - assert(aaiSI.getUri()!=null); - } - -} diff --git a/common/src/test/java/org/openecomp/mso/client/dmaap/DmaapClientTest.java b/common/src/test/java/org/openecomp/mso/client/dmaap/DmaapClientTest.java deleted file mode 100644 index dda7754712..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/dmaap/DmaapClientTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.dmaap; - -import static org.junit.Assert.assertEquals; - -import java.io.FileNotFoundException; -import java.io.IOException; - -import org.junit.Test; -import org.openecomp.mso.client.sdno.dmaap.SDNOHealthCheckDmaapConsumer; - -public class DmaapClientTest { - - @Test - public void deobfuscateTest() throws FileNotFoundException, IOException { - String encodedBase64 = "dGVzdHBhc3N3b3Jk"; - String notEncoded = "testpassword"; - DmaapConsumer consumer = new SDNOHealthCheckDmaapConsumer(); - assertEquals("decoded password", notEncoded, consumer.deobfuscatePassword(encodedBase64)); - - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/dmaap/DmaapPublisherTest.java b/common/src/test/java/org/openecomp/mso/client/dmaap/DmaapPublisherTest.java deleted file mode 100644 index a9bf81d2ad..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/dmaap/DmaapPublisherTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.openecomp.mso.client.dmaap; - -import org.junit.Test; - -import javax.ws.rs.ProcessingException; -import java.io.IOException; -import java.util.Optional; - -public class DmaapPublisherTest { - - DmaapPublisher dmaapPublisher = new DmaapPublisher(120) { - @Override - public String getUserName() { - return "test"; - } - - @Override - public String getPassword() { - return "test"; - } - - @Override - public String getTopic() { - return "test"; - } - - @Override - public Optional getHost() { - return Optional.of("http://localhost:8080"); - } - }; - - public DmaapPublisherTest() throws IOException { - } - - @Test(expected = ProcessingException.class) - public void sendTest() throws Exception { - dmaapPublisher.send("{'key': 'value'}"); - } - -} \ No newline at end of file diff --git a/common/src/test/java/org/openecomp/mso/client/grm/GRMBeansTest.java b/common/src/test/java/org/openecomp/mso/client/grm/GRMBeansTest.java deleted file mode 100644 index e22dc7b754..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/grm/GRMBeansTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.grm; - -import java.util.List; - -import org.junit.Test; - -import com.openpojo.reflection.PojoClass; -import com.openpojo.reflection.PojoClassFilter; -import com.openpojo.reflection.filters.FilterEnum; -import com.openpojo.reflection.filters.FilterPackageInfo; -import com.openpojo.reflection.impl.PojoClassFactory; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.affirm.Affirm; -import com.openpojo.validation.rule.impl.GetterMustExistRule; -import com.openpojo.validation.rule.impl.SetterMustExistRule; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; - -public class GRMBeansTest { - private static final String POJO_PACKAGE = "org.openecomp.mso.client.grm.beans"; - private PojoClassFilter filterTestClasses = new FilterTestClasses(); - - @Test - public void testPojoStructureAndBehavior() { - Validator validator = ValidatorBuilder.create() - .with(new GetterMustExistRule()) - .with(new SetterMustExistRule()) - .with(new SetterTester()) - .with(new GetterTester()) - .build(); - - validator.validate(POJO_PACKAGE, new FilterPackageInfo(), new FilterEnum(), filterTestClasses); - } - - private static class FilterTestClasses implements PojoClassFilter { - public boolean include(PojoClass pojoClass) { - return !pojoClass.getSourcePath().contains("/test-classes/"); - } - } - -} diff --git a/common/src/test/java/org/openecomp/mso/client/grm/GRMClientTest.java b/common/src/test/java/org/openecomp/mso/client/grm/GRMClientTest.java deleted file mode 100644 index 6865bbd773..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/grm/GRMClientTest.java +++ /dev/null @@ -1,185 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.grm; - -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.*; - -import java.io.File; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; - -import javax.ws.rs.core.MediaType; - -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.openecomp.mso.client.grm.exceptions.GRMClientCallFailed; -import org.openecomp.mso.client.grm.GRMClient; -import org.openecomp.mso.client.grm.beans.ServiceEndPointRequest; -import org.openecomp.mso.client.grm.beans.OperationalInfo; -import org.openecomp.mso.client.grm.beans.Property; -import org.openecomp.mso.client.grm.beans.ServiceEndPoint; -import org.openecomp.mso.client.grm.beans.ServiceEndPointList; -import org.openecomp.mso.client.grm.beans.ServiceEndPointLookupRequest; -import org.openecomp.mso.client.grm.beans.Version; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.tomakehurst.wiremock.junit.WireMockRule; -import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; - -public class GRMClientTest { - - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(28090)); - - private ObjectMapper mapper = new ObjectMapper(); - - @Test - public void testFind() throws Exception { - String endpoints = getFileContentsAsString("__files/grm/endpoints.json"); - wireMockRule.stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning")) - .willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", MediaType.APPLICATION_JSON) - .withBody(endpoints))); - - - GRMClient client = new GRMClient(); - ServiceEndPointList sel = client.findRunningServices("TEST.ECOMP_PSL.*", 1, "TEST"); - List list = sel.getServiceEndPointList(); - assertEquals(3, list.size()); - } - - @Test(expected = GRMClientCallFailed.class) - public void testFindFail() throws Exception { - - wireMockRule.stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning")) - .willReturn(aResponse() - .withStatus(400) - .withHeader("Content-Type", MediaType.APPLICATION_JSON) - .withBody(""))); - - GRMClient client = new GRMClient(); - client.findRunningServices("TEST.ECOMP_PSL.*", 1, "TEST"); - } - - @Ignore - @Test - public void testAdd() throws Exception { - - wireMockRule.stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/add")) - .willReturn(aResponse() - .withStatus(202) - .withHeader("Content-Type", MediaType.APPLICATION_JSON) - .withBody("test"))); - wireMockRule.addMockServiceRequestListener((request, response) -> { - System.out.println("URL Requested => " + request.getAbsoluteUrl()); - System.out.println("Request Body => " + request.getBodyAsString()); - System.out.println("Request Headers => " + request.getHeaders().toString()); - System.out.println("Response Status => " + response.getStatus()); - System.out.println("Response Body => " + response.getBodyAsString()); - }); - - Version ver = new Version(); - ver.setMajor(1); - ver.setMinor(0); - ver.setPatch("0"); - - ServiceEndPoint sep = new ServiceEndPoint(); - sep.setName("TEST.ECOMP_PSL.Inventory"); - sep.setVersion(ver); - sep.setHostAddress("127.0.0.1"); - sep.setListenPort("8080"); - sep.setLatitude("37.7022"); - sep.setLongitude("121.9358"); - sep.setContextPath("/"); - sep.setRouteOffer("TEST"); - - OperationalInfo operInfo = new OperationalInfo(); - operInfo.setCreatedBy("edge"); - operInfo.setUpdatedBy("edge"); - - sep.setOperationalInfo(operInfo); - - Property prop1 = new Property(); - prop1.setName("Environment"); - prop1.setValue("TEST"); - - Property prop2 = new Property(); - prop2.setName("cpfrun_cluster_name"); - prop2.setValue("testcase_cluster_no_cluster"); - - List props = new ArrayList(); - props.add(prop1); - props.add(prop2); - - sep.setProperties(props); - - ServiceEndPointRequest request = new ServiceEndPointRequest(); - request.setEnv("DEV"); - request.setServiceEndPoint(sep); - - System.out.println("Request in JSON: " + mapper.writeValueAsString(request)); - - GRMClient client = new GRMClient(); - client.addServiceEndPoint(request); - } - - @Test(expected = GRMClientCallFailed.class) - public void testAddFail() throws Exception { - wireMockRule.stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/add")) - .willReturn(aResponse() - .withStatus(404) - .withHeader("Content-Type", MediaType.APPLICATION_JSON) - .withBody("test"))); - ServiceEndPointRequest request = new ServiceEndPointRequest(); - GRMClient client = new GRMClient(); - client.addServiceEndPoint(request); - } - - @Test - public void testBuildServiceEndPointLookupRequest() { - GRMClient client = new GRMClient(); - ServiceEndPointLookupRequest request = client.buildServiceEndPointlookupRequest("TEST.ECOMP_PSL.Inventory", 1, "DEV"); - assertEquals("TEST.ECOMP_PSL.Inventory", request.getServiceEndPoint().getName()); - assertEquals(Integer.valueOf(1), Integer.valueOf(request.getServiceEndPoint().getVersion().getMajor())); - assertEquals("DEV", request.getEnv()); - - } - - protected String getFileContentsAsString(String fileName) { - String content = ""; - try { - ClassLoader classLoader = this.getClass().getClassLoader(); - File file = new File(classLoader.getResource(fileName).getFile()); - content = new String(Files.readAllBytes(file.toPath())); - } - catch(Exception e) { - e.printStackTrace(); - System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage()); - } - return content; - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/grm/ServiceEndPointListTest.java b/common/src/test/java/org/openecomp/mso/client/grm/ServiceEndPointListTest.java deleted file mode 100644 index 111fec46eb..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/grm/ServiceEndPointListTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.grm; - -import java.io.File; -import java.nio.file.Files; -import java.util.List; -import static org.junit.Assert.*; -import org.junit.Test; -import org.openecomp.mso.client.grm.beans.ServiceEndPoint; -import org.openecomp.mso.client.grm.beans.ServiceEndPointList; - -import com.fasterxml.jackson.databind.ObjectMapper; - -public class ServiceEndPointListTest { - - private ObjectMapper mapper = new ObjectMapper(); - - @Test - public void testUnmarshall() throws Exception { - String endpointsJson = getFileContentsAsString("__files/grm/endpoints.json"); - ServiceEndPointList sel = mapper.readValue(endpointsJson, ServiceEndPointList.class); - - List list = sel.getServiceEndPointList(); - ServiceEndPoint se = list.get(0); - - assertEquals(3, list.size()); - assertEquals("dummy.pod.ns.dummy-pod3", se.getName()); - assertEquals(Integer.valueOf(1), Integer.valueOf(se.getVersion().getMajor())); - assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getMinor())); - assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getPatch())); - assertEquals("135.144.120.218", se.getHostAddress()); - assertEquals("32004", se.getListenPort()); - assertEquals("37.7022", se.getLatitude()); - assertEquals("121.9358", se.getLongitude()); - assertEquals("/", se.getContextPath()); - assertEquals("edge", se.getOperationalInfo().getCreatedBy()); - assertEquals("edge", se.getOperationalInfo().getUpdatedBy()); - assertEquals("Environment", se.getProperties().get(0).getName()); - assertEquals("DEV", se.getProperties().get(0).getValue()); - } - - protected String getFileContentsAsString(String fileName) { - - String content = ""; - try { - ClassLoader classLoader = this.getClass().getClassLoader(); - File file = new File(classLoader.getResource(fileName).getFile()); - content = new String(Files.readAllBytes(file.toPath())); - } - catch(Exception e) { - e.printStackTrace(); - System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage()); - } - return content; - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/grm/ServiceEndPointRequestTest.java b/common/src/test/java/org/openecomp/mso/client/grm/ServiceEndPointRequestTest.java deleted file mode 100644 index 230b58bd84..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/grm/ServiceEndPointRequestTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.grm; - -import static org.junit.Assert.assertEquals; -import java.util.ArrayList; -import java.util.List; -import org.junit.Test; -import org.openecomp.mso.client.grm.beans.OperationalInfo; -import org.openecomp.mso.client.grm.beans.Property; -import org.openecomp.mso.client.grm.beans.ServiceEndPoint; -import org.openecomp.mso.client.grm.beans.ServiceEndPointRequest; -import org.openecomp.mso.client.grm.beans.Version; - -import com.fasterxml.jackson.databind.ObjectMapper; - -public class ServiceEndPointRequestTest { - - private ObjectMapper mapper = new ObjectMapper(); - - @Test - public void testMarshall() throws Exception { - - String expected = - "{\"serviceEndPoint\":{\"name\":\"TEST.ECOMP_PSL.Inventory\",\"version\":{\"major\":1,\"minor\":0,\"patch\":\"0\"}," + - "\"hostAddress\":\"127.0.0.1\",\"listenPort\":\"8080\",\"latitude\":\"37.7022\",\"longitude\":\"121.9358\"," + - "\"contextPath\":\"/\",\"routeOffer\":\"TEST\",\"operationalInfo\":{\"createdBy\":\"edge\",\"updatedBy\":\"edge\"}," + - "\"properties\":[{\"name\":\"Environment\",\"value\":\"TEST\"},{\"name\":\"cpfrun_cluster_name\"," + - "\"value\":\"testcase_cluster_no_cluster\"}]},\"env\":\"DEV\"}"; - - Version ver = new Version(); - ver.setMajor(1); - ver.setMinor(0); - ver.setPatch("0"); - - ServiceEndPoint sep = new ServiceEndPoint(); - sep.setName("TEST.ECOMP_PSL.Inventory"); - sep.setVersion(ver); - sep.setHostAddress("127.0.0.1"); - sep.setListenPort("8080"); - sep.setLatitude("37.7022"); - sep.setLongitude("121.9358"); - sep.setContextPath("/"); - sep.setRouteOffer("TEST"); - - OperationalInfo operInfo = new OperationalInfo(); - operInfo.setCreatedBy("edge"); - operInfo.setUpdatedBy("edge"); - - sep.setOperationalInfo(operInfo); - - Property prop1 = new Property(); - prop1.setName("Environment"); - prop1.setValue("TEST"); - - Property prop2 = new Property(); - prop2.setName("cpfrun_cluster_name"); - prop2.setValue("testcase_cluster_no_cluster"); - - List props = new ArrayList(); - props.add(prop1); - props.add(prop2); - - sep.setProperties(props); - - ServiceEndPointRequest request = new ServiceEndPointRequest(); - request.setEnv("DEV"); - request.setServiceEndPoint(sep); - - assertEquals(expected, mapper.writeValueAsString(request)); - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/policy/PolicyClientImplTest.java b/common/src/test/java/org/openecomp/mso/client/policy/PolicyClientImplTest.java deleted file mode 100644 index f406667870..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/policy/PolicyClientImplTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.policy; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doReturn; -import static com.shazam.shazamcrest.MatcherAssert.assertThat; -import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; - -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.Mockito; -import org.openecomp.mso.client.defaultproperties.PolicyRestPropertiesImpl; -import org.openecomp.mso.client.policy.entities.DecisionAttributes; -import org.openecomp.mso.client.policy.entities.DictionaryData; -import org.openecomp.mso.client.policy.entities.PolicyDecision; -import org.openecomp.mso.client.policy.entities.PolicyServiceType; - -public class PolicyClientImplTest { - - @Test - public void successReadProperties() { - PolicyRestClient client = new PolicyRestClient(new PolicyRestPropertiesImpl(), PolicyServiceType.GET_DECISION); - client.initializeHeaderMap(client.headerMap); - - assertEquals("Found expected Client Auth", client.headerMap.get("ClientAuth"), - "Basic bTAzNzQzOnBvbGljeVIwY2sk"); - assertEquals("Found expected Authorization", client.headerMap.get("Authorization"), - "Basic dGVzdHBkcDphbHBoYTEyMw=="); - assertEquals("Found expected Environment", client.headerMap.get("Environment"), "TEST"); - assertEquals("Has X-ECOMP-RequestID", client.headerMap.containsKey("X-ECOMP-RequestID"), true); - } - - @Test - public void getDecisionMockTest() { - String serviceType = "S"; - String vnfType = "V"; - String bbID = "BB1"; - String workStep = "1"; - String errorCode = "123"; - - PolicyDecision expected = new PolicyDecision(); - expected.setDecision("PERMIT"); - expected.setDetails("Retry"); - - DecisionAttributes decisionAttributes = new DecisionAttributes(); - decisionAttributes.setServiceType(serviceType); - decisionAttributes.setVNFType(vnfType); - decisionAttributes.setBBID(bbID); - decisionAttributes.setWorkStep(workStep); - decisionAttributes.setErrorCode(errorCode); - PolicyClient client = Mockito.spy(PolicyClientImpl.class); - - doReturn(expected).when(client).getDecision(serviceType, vnfType, bbID, workStep, errorCode); - - PolicyDecision actual = client.getDecision(serviceType, vnfType, bbID, workStep, errorCode); - assertThat(actual, sameBeanAs(expected)); - } - - @Test - @Ignore - public void getDecisionTest() { - PolicyClient client = new PolicyClientImpl(); - PolicyDecision decision = client.getDecision("S", "V", "BB1", "1", "123"); - assertEquals("Decision is correct", decision.getDecision(), "PERMIT"); - assertEquals("Decision details is correct", decision.getDetails(), "Retry"); - } - - @Test - @Ignore - public void getAllowedTreatmentsTest() { - PolicyClient client = new PolicyClientImpl(); - DictionaryData dictClient = client.getAllowedTreatments("BB1", "1"); - final String dictBbidString = dictClient.getBbid().getString(); - final String dictWorkStepString = dictClient.getWorkstep().getString(); - assertEquals("DictionaryData matches a response Bbid", dictBbidString, "BB1"); - assertEquals("DicitonaryData matches a response WorkStep", dictWorkStepString, "1"); - } - /* - * @Test public void getAllowedTreatmentsTest() { PolicyClient client = new - * PolicyClientImpl(); AllowedTreatments allowedTreatments = - * client.getAllowedTreatments("BB1", "1"); int expectedSizeOfList = 4; int - * sizeOfList = allowedTreatments.getAllowedTreatments().size(); - * assertEquals("Decision is correct", sizeOfList, expectedSizeOfList); } - */ -} diff --git a/common/src/test/java/org/openecomp/mso/client/policy/entities/PolicyEntitiesTest.java b/common/src/test/java/org/openecomp/mso/client/policy/entities/PolicyEntitiesTest.java deleted file mode 100644 index f526e10249..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/policy/entities/PolicyEntitiesTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.policy.entities; - -import org.junit.Test; - -import com.openpojo.reflection.PojoClass; -import com.openpojo.reflection.PojoClassFilter; -import com.openpojo.reflection.filters.FilterEnum; -import com.openpojo.reflection.filters.FilterPackageInfo; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.rule.impl.GetterMustExistRule; -import com.openpojo.validation.rule.impl.SetterMustExistRule; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; - -public class PolicyEntitiesTest { - - private PojoClassFilter filterTestClasses = new FilterTestClasses(); - - @Test - public void pojoStructure() { - test("org.openecomp.mso.client.policy.entities"); - } - - private void test(String pojoPackage) { - Validator validator = ValidatorBuilder.create() - .with(new GetterMustExistRule()) - .with(new SetterMustExistRule()) - .with(new SetterTester()) - .with(new GetterTester()) - .build(); - validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses); - } - private static class FilterTestClasses implements PojoClassFilter { - public boolean include(PojoClass pojoClass) { - return !pojoClass.getSourcePath().contains("/test-classes/"); - } - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/ruby/RubyCheckClientTest.java b/common/src/test/java/org/openecomp/mso/client/ruby/RubyCheckClientTest.java deleted file mode 100644 index 053f1f2533..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/ruby/RubyCheckClientTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.ruby; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.text.ParseException; -import java.time.format.DateTimeFormatter; - -import org.junit.Test; -import org.openecomp.mso.client.ruby.beans.Ruby; - -import static org.apache.commons.lang3.StringUtils.*; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class RubyCheckClientTest { - private final String fileLocation = "src/test/resources/org/openecomp/mso/client/ruby/create-ticket/"; - private static final String REQUEST_ID = "abc123"; - private static final String SOURCE_NAME = "source-name"; - private static final String TIME = "test-time"; - private static final String REASON = "reason"; - private static final String WORK_FLOW_ID = "work-flow-Id"; - private static final String NOTIFICATION = "notification"; - - - - @Test - public void verifyRubyCreateTicketRequest() throws IOException, ParseException{ - String content = this.getJson("create-ticket-request.json"); - ObjectMapper mapper = new ObjectMapper(); - Ruby expected = mapper.readValue(content, Ruby.class); - RubyClient client = new RubyClient(); - RubyClient spy = spy(client); - when(spy.getTime()).thenReturn(TIME); - String actual = spy.buildRequest(REQUEST_ID, SOURCE_NAME, REASON, WORK_FLOW_ID, NOTIFICATION); - assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); - } - - - @Test - public void verifyTimeFormat() { - RubyClient client = new RubyClient(); - String time = client.getTime(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss Z"); - formatter.parse(time); - } - - - @Test - public void verifyReasonCharLimit() throws IOException{ - final String reasonLong = repeat("*", 256); - RubyClient client = new RubyClient(); - try{ - client.buildRequest(REQUEST_ID, SOURCE_NAME, reasonLong, WORK_FLOW_ID, NOTIFICATION); - fail("Should have thrown IllegalArgumentException but did not!"); - } - catch(final IllegalArgumentException e){ - final String msg = "reason exceeds 255 characters"; - assertEquals(msg, e.getMessage()); - } - } - - @Test - public void verifyNotificationCharLimit() throws IOException{ - final String notificationLong = repeat("*", 1025); - RubyClient client = new RubyClient(); - try{ - client.buildRequest(REQUEST_ID, SOURCE_NAME, REASON, WORK_FLOW_ID, notificationLong); - fail("Should have thrown IllegalArgumentException but did not!"); - } - catch(final IllegalArgumentException e){ - final String msg = "notification exceeds 1024 characters"; - assertEquals(msg, e.getMessage()); - } - } - - private String getJson(String filename) throws IOException { - return new String(Files.readAllBytes(Paths.get(fileLocation + filename))); - } - -} - diff --git a/common/src/test/java/org/openecomp/mso/client/ruby/beans/RubyBeansTest.java b/common/src/test/java/org/openecomp/mso/client/ruby/beans/RubyBeansTest.java deleted file mode 100644 index 90e1861292..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/ruby/beans/RubyBeansTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.ruby.beans; - -import org.junit.Test; - -import com.openpojo.reflection.PojoClass; -import com.openpojo.reflection.PojoClassFilter; -import com.openpojo.reflection.filters.FilterEnum; -import com.openpojo.reflection.filters.FilterPackageInfo; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.rule.impl.GetterMustExistRule; -import com.openpojo.validation.rule.impl.SetterMustExistRule; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; - -public class RubyBeansTest { - - private PojoClassFilter filterTestClasses = new FilterTestClasses(); - - @Test - public void pojoStructure() { - test("org.openecomp.mso.client.ruby.beans"); - } - - private void test(String pojoPackage) { - Validator validator = ValidatorBuilder.create() - .with(new GetterMustExistRule()) - .with(new SetterMustExistRule()) - .with(new SetterTester()) - .with(new GetterTester()) - .build(); - validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses); - } - private static class FilterTestClasses implements PojoClassFilter { - public boolean include(PojoClass pojoClass) { - return !pojoClass.getSourcePath().contains("/test-classes/"); - } - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/sdno/SDNOHealthCheckClientTest.java b/common/src/test/java/org/openecomp/mso/client/sdno/SDNOHealthCheckClientTest.java deleted file mode 100644 index 6c64d90ff4..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/sdno/SDNOHealthCheckClientTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.sdno; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Optional; - -import org.junit.Test; -import org.openecomp.mso.client.sdno.beans.SDNO; - -import com.fasterxml.jackson.databind.ObjectMapper; - -public class SDNOHealthCheckClientTest { - - - - private final String fileLocation = "src/test/resources/org/openecomp/mso/client/sdno/health-check/"; - private static final String userId = "test-user"; - private static final Optional clliCode = Optional.of("test-clli"); - private static final String requestId = "test-request-id"; - private static final String configurationId = "test-configuration-id"; - private static final String interfaceId = "test-interface-id"; - - @Test - public void verfyLPortMirrorPreCheckRequest() throws IOException{ - String content = this.getJson("custom-lport-mirror-pre-check-request.json"); - ObjectMapper mapper = new ObjectMapper(); - SDNO expected = mapper.readValue(content, SDNO.class); - SDNOHealthCheckClient client = new SDNOHealthCheckClient(); - String actual = client.buildLPortMirrorCheckPreRequest(userId, requestId, clliCode, configurationId, interfaceId); - assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); - } - - @Test - public void verfyLPortMirrorPostCheckRequest() throws IOException{ - String content = this.getJson("custom-lport-mirror-post-check-request.json"); - ObjectMapper mapper = new ObjectMapper(); - SDNO expected = mapper.readValue(content, SDNO.class); - SDNOHealthCheckClient client = new SDNOHealthCheckClient(); - String actual = client.buildLPortMirrorCheckPostRequest(userId, requestId, clliCode, configurationId, interfaceId); - assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); - } - - - @Test - public void verifyPortMirrorPostCheckRequest() throws IOException{ - String content = this.getJson("custom-port-mirror-post-check-request.json"); - ObjectMapper mapper = new ObjectMapper(); - SDNO expected = mapper.readValue(content, SDNO.class); - SDNOHealthCheckClient client = new SDNOHealthCheckClient(); - String actual = client.buildPortMirrorPostCheckRequest(userId, requestId, clliCode, configurationId); - - assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); - - } - @Test - public void verifyPortMirrorPreCheckRequest() throws IOException { - String content = this.getJson("custom-port-mirror-pre-check-request.json"); - ObjectMapper mapper = new ObjectMapper(); - SDNO expected = mapper.readValue(content, SDNO.class); - SDNOHealthCheckClient client = new SDNOHealthCheckClient(); - String actual = client.buildPortMirrorPreCheckRequest(userId, requestId, clliCode, configurationId); - - assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); - - } - - private String getJson(String filename) throws IOException { - return new String(Files.readAllBytes(Paths.get(fileLocation + filename))); - } - -} diff --git a/common/src/test/java/org/openecomp/mso/client/sdno/SDNOValidatorTest.java b/common/src/test/java/org/openecomp/mso/client/sdno/SDNOValidatorTest.java deleted file mode 100644 index cd84e7854d..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/sdno/SDNOValidatorTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.sdno; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.UUID; - -import org.hamcrest.core.StringContains; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.Spy; -import org.onap.aai.domain.yang.GenericVnf; -import org.openecomp.mso.client.dmaap.Consumer; -import org.openecomp.mso.client.dmaap.exceptions.DMaaPConsumerFailure; -import org.openecomp.mso.client.exceptions.SDNOException; -import org.openecomp.mso.client.sdno.beans.SDNO; -import org.openecomp.mso.client.sdno.dmaap.SDNOHealthCheckDmaapConsumer; - -import com.fasterxml.jackson.databind.ObjectMapper; - - -public class SDNOValidatorTest { - - - @Mock private Consumer mrConsumer; - @Spy private SDNOHealthCheckDmaapConsumer dmaapConsumer; - private final String fileLocation = "src/test/resources/org/openecomp/mso/client/sdno/"; - private final String uuid = "xyz123"; - @Rule public ExpectedException thrown = ExpectedException.none(); - - @Before - public void setUpTests() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void success() throws IOException, Exception { - when(dmaapConsumer.getConsumer()).thenReturn(mrConsumer); - when(mrConsumer.fetch()).thenReturn(Arrays.asList(new String[]{getJson("response.json"), getJson("output-success.json")})); - - SDNOValidatorImpl validator = new SDNOValidatorImpl(); - SDNOValidatorImpl spy = spy(validator); - when(dmaapConsumer.getRequestId()).thenReturn("xyz123"); - doReturn(dmaapConsumer).when(spy).getConsumer(any(String.class)); - boolean result = spy.pollForResponse("xyz123"); - assertEquals("result is true", result, true); - } - - @Test - public void failure() throws IOException, Exception { - when(dmaapConsumer.getConsumer()).thenReturn(mrConsumer); - when(mrConsumer.fetch()).thenReturn(Arrays.asList(new String[]{getJson("response.json"), getJson("output-failure.json")})); - - SDNOValidatorImpl validator = new SDNOValidatorImpl(); - SDNOValidatorImpl spy = spy(validator); - when(dmaapConsumer.getRequestId()).thenReturn("xyz123"); - doReturn(dmaapConsumer).when(spy).getConsumer(any(String.class)); - thrown.expect(SDNOException.class); - thrown.expectMessage(new StringContains("my error message")); - boolean result = spy.pollForResponse("xyz123"); - - } - @Ignore - @Test - public void run() throws Exception { - SDNOValidatorImpl validator = new SDNOValidatorImpl(); - UUID uuid = UUID.randomUUID(); - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("test"); - vnf.setIpv4OamAddress("1.2.3.4"); - vnf.setVnfType("VPE"); - SDNO request = validator.buildRequestDiagnostic(vnf, uuid, "mechid"); - ObjectMapper mapper = new ObjectMapper(); - String json = mapper.writeValueAsString(request); - validator.submitRequest(json); - thrown.expect(DMaaPConsumerFailure.class); - boolean result = validator.pollForResponse(uuid.toString()); - System.out.println(json); - - } - private String getJson(String filename) throws IOException { - return new String(Files.readAllBytes(Paths.get(fileLocation + filename))); - } -} diff --git a/common/src/test/java/org/openecomp/mso/client/sdno/beans/SdnoBeansTest.java b/common/src/test/java/org/openecomp/mso/client/sdno/beans/SdnoBeansTest.java deleted file mode 100644 index 4a2580f3f1..0000000000 --- a/common/src/test/java/org/openecomp/mso/client/sdno/beans/SdnoBeansTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.client.sdno.beans; - -import org.junit.Test; - -import com.openpojo.reflection.PojoClass; -import com.openpojo.reflection.PojoClassFilter; -import com.openpojo.reflection.filters.FilterEnum; -import com.openpojo.reflection.filters.FilterPackageInfo; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.rule.impl.GetterMustExistRule; -import com.openpojo.validation.rule.impl.SetterMustExistRule; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; - -public class SdnoBeansTest { - - private PojoClassFilter filterTestClasses = new FilterTestClasses(); - - @Test - public void pojoStructure() { - test("org.openecomp.mso.client.sdno.beans"); - } - - private void test(String pojoPackage) { - Validator validator = ValidatorBuilder.create() - .with(new GetterMustExistRule()) - .with(new SetterMustExistRule()) - .with(new SetterTester()) - .with(new GetterTester()) - .build(); - validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses); - } - private static class FilterTestClasses implements PojoClassFilter { - public boolean include(PojoClass pojoClass) { - return !pojoClass.getSourcePath().contains("/test-classes/"); - } - } -} diff --git a/common/src/test/java/org/openecomp/mso/entity/MsoRequestTest.java b/common/src/test/java/org/openecomp/mso/entity/MsoRequestTest.java deleted file mode 100644 index a7fc7e223e..0000000000 --- a/common/src/test/java/org/openecomp/mso/entity/MsoRequestTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.entity; - -import org.junit.Test; -import org.openecomp.mso.openpojo.rules.HasToStringRule; -import org.openecomp.mso.openpojo.rules.ToStringTester; - -import com.openpojo.reflection.PojoClass; -import com.openpojo.reflection.PojoClassFilter; -import com.openpojo.reflection.filters.FilterEnum; -import com.openpojo.reflection.filters.FilterPackageInfo; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.rule.impl.GetterMustExistRule; -import com.openpojo.validation.rule.impl.SetterMustExistRule; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; - - -public class MsoRequestTest { - - private PojoClassFilter filterTestClasses = new FilterTestClasses(); - - @Test - public void pojoStructure() { - test("org.openecomp.mso.entity"); - } - - private void test(String pojoPackage) { - Validator validator = ValidatorBuilder.create() - .with(new GetterMustExistRule()) - .with(new SetterMustExistRule()) - .with(new SetterTester()) - .with(new GetterTester()) - .build(); - validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses); - } - private static class FilterTestClasses implements PojoClassFilter { - public boolean include(PojoClass pojoClass) { - return !pojoClass.getSourcePath().contains("/test-classes/"); - } - } - -} - diff --git a/common/src/test/java/org/openecomp/mso/jsonpath/JsonPathUtilTest.java b/common/src/test/java/org/openecomp/mso/jsonpath/JsonPathUtilTest.java deleted file mode 100644 index 85bb8b6804..0000000000 --- a/common/src/test/java/org/openecomp/mso/jsonpath/JsonPathUtilTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.jsonpath; - -import static org.junit.Assert.assertEquals; - -import java.util.Optional; - -import org.junit.Test; - -public class JsonPathUtilTest { - - private static final String json = "{\"test\" : \"hello\", \"test2\" : {\"nested\" : \"value\"}}"; - @Test - public void pathExistsTest() { - assertEquals("test is found", JsonPathUtil.getInstance().pathExists(json, "$.test"), true); - assertEquals("nothing is not found", JsonPathUtil.getInstance().pathExists(json, "$.nothing"), false); - } - - @Test - public void locateResultTest() { - assertEquals("value of hello is found", Optional.of("hello"), JsonPathUtil.getInstance().locateResult(json, "$.test")); - assertEquals("nothing returns empty", Optional.empty(), JsonPathUtil.getInstance().locateResult(json, "$.nothing")); - } - - @Test - public void simpleAndComplexValues() { - assertEquals("json doc found", Optional.of("{\"nested\":\"value\"}"), JsonPathUtil.getInstance().locateResult(json, "$.test2")); - assertEquals("value found", Optional.of("value"), JsonPathUtil.getInstance().locateResult(json, "$.test2.nested")); - } -} \ No newline at end of file diff --git a/common/src/test/java/org/openecomp/mso/serviceinstancebeans/ServiceInstanceBeansTest.java b/common/src/test/java/org/openecomp/mso/serviceinstancebeans/ServiceInstanceBeansTest.java deleted file mode 100644 index f0853305ee..0000000000 --- a/common/src/test/java/org/openecomp/mso/serviceinstancebeans/ServiceInstanceBeansTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.serviceinstancebeans; - -import org.junit.Test; -import org.openecomp.mso.openpojo.rules.HasToStringRule; -import org.openecomp.mso.openpojo.rules.ToStringTester; - -import com.openpojo.reflection.PojoClass; -import com.openpojo.reflection.PojoClassFilter; -import com.openpojo.reflection.filters.FilterEnum; -import com.openpojo.reflection.filters.FilterPackageInfo; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.rule.impl.GetterMustExistRule; -import com.openpojo.validation.rule.impl.SetterMustExistRule; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; - -public class ServiceInstanceBeansTest { - - private PojoClassFilter filterTestClasses = new FilterTestClasses(); - - @Test - public void pojoStructure() { - test("org.openecomp.mso.serviceinstancebeans"); - } - - private void test(String pojoPackage) { - Validator validator = ValidatorBuilder.create() - .with(new GetterMustExistRule()) - .with(new SetterMustExistRule()) - .with(new HasToStringRule()) - .with(new SetterTester()) - .with(new GetterTester()) - .with(new ToStringTester()) - .build(); - validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses); - } - private static class FilterTestClasses implements PojoClassFilter { - public boolean include(PojoClass pojoClass) { - return !pojoClass.getSourcePath().contains("/test-classes/"); - } - } - -} diff --git a/common/src/test/java/org/openecomp/mso/serviceinstancebeans/ServiceInstancesRequestTest.java b/common/src/test/java/org/openecomp/mso/serviceinstancebeans/ServiceInstancesRequestTest.java deleted file mode 100644 index 28cbe799cd..0000000000 --- a/common/src/test/java/org/openecomp/mso/serviceinstancebeans/ServiceInstancesRequestTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.serviceinstancebeans; - -import org.junit.Assert; -import org.junit.Test; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class ServiceInstancesRequestTest { - - @Test - public void serializeServiceInstance() { - String incomingRequest = "{\"requestDetails\":{\"modelInfo\":{\"modelInvariantUuid\":\"9647dfc4-2083-11e7-93ae-92361f002672\",\"modelType\":\"configuration\",\"modelName\":\"MSO-Configuration\",\"modelVersion\":\"1.0\",\"modelUuid\":\"36a3a8ea-49a6-4ac8-b06c-89a545444455\",\"modelCustomizationUuid\":\"68dc9a92-214c-11e7-93ae-92361f002671\"},\"requestInfo\":{\"source\":\"VID\",\"instanceName\":\"port_mirror_config_m830-01\",\"suppressRollback\":false,\"requestorId\":\"mdg1215\"},\"relatedInstanceList\":[{\"relatedInstance\":{\"instanceId\":\"956121e0-542d-4b30-b8c7-be611e3c8f13\",\"modelInfo\":{\"modelInvariantUuid\":\"9647dfc4-2083-11e7-93ae-92361f002671\",\"modelType\":\"service\",\"modelName\":\"MSOTADevInfra_vSAMP10a_Service\",\"modelVersion\":\"1.0\",\"modelUuid\":\"5df8b6de-2083-11e7-93ae-92361f002671\"}}},{\"relatedInstance\":{\"instanceId\":\"956121e0-542d-4b30-b8c7-be611e3c8f11\",\"modelInfo\":{\"modelInvariantUuid\":\"36a3a8ea-49a6-4ac8-b06c-89a545444456\",\"modelType\":\"vnf\",\"modelName\":\"testvnf\",\"modelVersion\":\"1.0\",\"modelUuid\":\"956121e0-542d-4b30-b8c7-be611e3c8f14\",\"modelCustomizationUuid\":\"68dc9a92-214c-11e7-93ae-92361f002676\"},\"instanceDirection\":\"source\"}},{\"relatedInstance\":{\"instanceId\":\"956121e0-542d-4b30-b8c7-be611e3c8f12\",\"modelInfo\":{\"modelInvariantUuid\":\"36a3a8ea-49a6-4ac8-b06c-89a545444477\",\"modelType\":\"vnf\",\"modelName\":\"svProbe vnf model name\",\"modelVersion\":\"1.0\",\"modelUuid\":\"36a3a8ea-49a6-4ac8-b06c-89a545444488\",\"modelCustomizationUuid\":\"68dc9a92-214c-11e7-93ae-92361f002672\"},\"instanceDirection\":\"destination\"}}],\"cloudConfiguration\":{\"lcpCloudRegionId\":\"mdt1\"},\"requestParameters\":{\"subscriptionServiceType\":\"MSO-dev-service-type\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"}],\"aLaCarte\":false,\"autoBuildVfModules\":false,\"cascadeDelete\":false,\"usePreload\":true,\"rebuildVolumeGroups\":false}},\"serviceInstanceId\":\"956121e0-542d-4b30-b8c7-be611e3c8f13\"}"; - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - try { - ServiceInstancesRequest request = mapper.readValue(incomingRequest, ServiceInstancesRequest.class); - System.out.println("Java Object: " + request); - } catch (Exception e) { - System.out.println("Caught Exception " + e.getMessage()); - Assert.fail("Caught error on object serialization"); - } - } -} diff --git a/common/src/test/java/org/openecomp/mso/utils/CheckResultsTest.java b/common/src/test/java/org/openecomp/mso/utils/CheckResultsTest.java deleted file mode 100644 index eeb7342d50..0000000000 --- a/common/src/test/java/org/openecomp/mso/utils/CheckResultsTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.utils; - -import java.util.List; - -import org.junit.Test; - -import org.openecomp.mso.utils.CheckResults.CheckResult; - -public class CheckResultsTest { - - /** - * Test method for {@link org.openecomp.mso.utils.CheckResults#getResults()}. - */ - @Test - public final void testGetResults () { - CheckResults cr = new CheckResults (); - cr.addHostCheckResult ("host1", 0, "output"); - cr.addHostCheckResult ("host2", 2, "output2"); - cr.addServiceCheckResult ("host1", "service1", 0, "outputServ"); - cr.addServiceCheckResult ("host1", "service2", 2, "outputServ2"); - cr.addServiceCheckResult ("host2", "service1", 0, "output2Serv"); - cr.addServiceCheckResult ("host2", "service2", 2, "output2Serv2"); - List res = cr.getResults (); - assert(res.size () == 6); - assert(res.get (0).getHostname ().equals ("host1")); - assert(res.get (1).getHostname ().equals ("host2")); - assert(res.get (2).getHostname ().equals ("host1")); - assert(res.get (3).getHostname ().equals ("host1")); - assert(res.get (4).getHostname ().equals ("host2")); - assert(res.get (5).getHostname ().equals ("host2")); - assert(res.get (0).getServicename () == null); - assert(res.get (3).getServicename ().equals ("service2")); - assert(res.get (5).getState () == 2); - } - -} diff --git a/common/src/test/java/org/openecomp/mso/utils/RootIgnoringObjectMapperTest.java b/common/src/test/java/org/openecomp/mso/utils/RootIgnoringObjectMapperTest.java deleted file mode 100644 index 1c7e845f16..0000000000 --- a/common/src/test/java/org/openecomp/mso/utils/RootIgnoringObjectMapperTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.utils; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonRootName; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class RootIgnoringObjectMapperTest { - - @Test - public void someObjectWithoutRootTest() throws Exception { - ObjectMapper mapper = new RootIgnoringObjectMapper(SomeObject.class); - - String content = "{" - + "\"attribute\":\"charm\"" - + "}"; - - SomeObject response = mapper.readValue(content, SomeObject.class); - assertEquals("SomeObject[attribute=charm]", response.toString()); - } - - @Test - public void someObjectWithRootTest() throws Exception { - ObjectMapper mapper = new RootIgnoringObjectMapper(SomeObject.class); - - String content = "{\"SomeObject\":{" - + "\"attribute\":\"charm\"" - + "}}"; - - SomeObject response = mapper.readValue(content, SomeObject.class); - assertEquals("SomeObject[attribute=charm]", response.toString()); - } - - @Test - public void annotatedObjectWithoutRootTest() throws Exception { - ObjectMapper mapper = new RootIgnoringObjectMapper(AnnotatedObject.class); - - String content = "{" - + "\"attribute\":\"charm\"" - + "}"; - - AnnotatedObject response = mapper.readValue(content, AnnotatedObject.class); - assertEquals("AnnotatedObject[attribute=charm]", response.toString()); - } - - @Test - public void annotatedObjectWithRootTest() throws Exception { - ObjectMapper mapper = new RootIgnoringObjectMapper(AnnotatedObject.class); - - String content = "{\"annotated-object\":{" - + "\"attribute\":\"charm\"" - + "}}"; - - AnnotatedObject response = mapper.readValue(content, AnnotatedObject.class); - assertEquals("AnnotatedObject[attribute=charm]", response.toString()); - } - - public static class SomeObject { - - @JsonProperty("attribute") - private String attribute; - - public String toString() { - return getClass().getSimpleName() + "[attribute=" + attribute + "]"; - } - } - - @JsonRootName(value = "annotated-object") - public static class AnnotatedObject extends SomeObject { - } -} \ No newline at end of file diff --git a/common/src/test/java/org/openecomp/mso/utils/UUIDCheckerTest.java b/common/src/test/java/org/openecomp/mso/utils/UUIDCheckerTest.java deleted file mode 100644 index fa00246e8b..0000000000 --- a/common/src/test/java/org/openecomp/mso/utils/UUIDCheckerTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.mso.utils; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.openecomp.mso.logger.MsoLogger; - -public class UUIDCheckerTest { - - private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL); - - @Test - public void testUUIDChecker() throws Exception { - boolean isValidUUID = UUIDChecker.isValidUUID("invalid-uuid"); - assertEquals(false, isValidUUID); - String validUUID = UUIDChecker.verifyOldUUID("invalid-uuid", LOGGER); - assertEquals(true, UUIDChecker.isValidUUID(validUUID)); - String generatedUUID = UUIDChecker.generateUUID(LOGGER); - assertEquals(true, UUIDChecker.isValidUUID(generatedUUID)); - String generatedServiceInstanceId = UUIDChecker.generateServiceInstanceID(LOGGER); - assertEquals(true, UUIDChecker.isValidUUID(generatedServiceInstanceId)); - } - -} diff --git a/common/src/test/resources/__files/aai/bulkprocess/test-request-small.json b/common/src/test/resources/__files/aai/bulkprocess/test-request-small.json new file mode 100644 index 0000000000..973928108f --- /dev/null +++ b/common/src/test/resources/__files/aai/bulkprocess/test-request-small.json @@ -0,0 +1,10 @@ +{ + "transactions" : [ { + "put" : [ { + "uri" : "/network/generic-vnfs/generic-vnf/test1/relationship-list/relationship", + "body" : { + "related-link" : "/cloud-infrastructure/pservers/pserver/test2" + } + } ] + } ] +} \ No newline at end of file diff --git a/common/src/test/resources/__files/aai/resources/e2e-complex.json b/common/src/test/resources/__files/aai/resources/e2e-complex.json index 6fc9cb36e6..21bacbd5ce 100644 --- a/common/src/test/resources/__files/aai/resources/e2e-complex.json +++ b/common/src/test/resources/__files/aai/resources/e2e-complex.json @@ -24,7 +24,7 @@ "relationship": [ { "related-to": "vpls-pe", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/network/vpls-pes/vpls-pe/sfcca301vr1", + "related-link": "https://localhost:8443/aai/v9/network/vpls-pes/vpls-pe/sfcca301vr1", "relationship-data": [ { "relationship-key": "vpls-pe.equipment-name", @@ -48,7 +48,7 @@ "relationship": [ { "related-to": "vce", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053", + "related-link": "https://localhost:8443/aai/v9/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053", "relationship-data": [ { "relationship-key": "vce.vnf-id", @@ -64,7 +64,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj104snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj104snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -79,7 +79,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj105snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj105snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -94,7 +94,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/compute_host", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/compute_host", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -109,7 +109,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj106snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj106snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -124,7 +124,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj126sd9", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj126sd9", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -139,7 +139,7 @@ }, { "related-to": "vce", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/network/vces/vce/8ae1e5f8-61f1-4c71-913a-b40cc4593cb9", + "related-link": "https://localhost:8443/aai/v9/network/vces/vce/8ae1e5f8-61f1-4c71-913a-b40cc4593cb9", "relationship-data": [ { "relationship-key": "vce.vnf-id", @@ -155,7 +155,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj102sta", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj102sta", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -170,7 +170,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnjtax102", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnjtax102", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -185,7 +185,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj107snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj107snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -200,7 +200,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj118snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj118snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -215,7 +215,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj110snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj110snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -230,7 +230,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj109snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj109snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -245,7 +245,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj114snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj114snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -260,7 +260,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj119snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj119snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -275,7 +275,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj116snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj116snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -290,7 +290,7 @@ }, { "related-to": "vce", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/network/vces/vce/a2935fa9-b743-49f4-9813-a127f13c4e93", + "related-link": "https://localhost:8443/aai/v9/network/vces/vce/a2935fa9-b743-49f4-9813-a127f13c4e93", "relationship-data": [ { "relationship-key": "vce.vnf-id", @@ -306,7 +306,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj108snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj108snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -321,7 +321,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj123sd9", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj123sd9", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -336,7 +336,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj101snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj101snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -351,7 +351,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj102snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj102snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -366,7 +366,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnjtax101", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnjtax101", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -381,7 +381,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj113snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj113snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -396,7 +396,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj111snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj111snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -411,7 +411,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj103snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj103snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -426,7 +426,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj117snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj117snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -441,7 +441,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj101sta", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj101sta", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -456,7 +456,7 @@ }, { "related-to": "vce", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/network/vces/vce/c7fe7698-8063-4e26-8bd3-ca3edde0b0d4", + "related-link": "https://localhost:8443/aai/v9/network/vces/vce/c7fe7698-8063-4e26-8bd3-ca3edde0b0d4", "relationship-data": [ { "relationship-key": "vce.vnf-id", @@ -472,7 +472,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj120snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj120snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -487,7 +487,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj124sd9", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj124sd9", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -502,7 +502,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj125sd9", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj125sd9", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -517,7 +517,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj112snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj112snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -532,7 +532,7 @@ }, { "related-to": "pserver", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj115snd", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/pservers/pserver/mtcnj115snd", "relationship-data": [ { "relationship-key": "pserver.hostname", @@ -547,7 +547,7 @@ }, { "related-to": "cloud-region", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/cloud-regions/cloud-region/att-aic/mtcnj2", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/cloud-regions/cloud-region/att-aic/mtcnj2", "relationship-data": [ { "relationship-key": "cloud-region.cloud-owner", @@ -567,7 +567,7 @@ }, { "related-to": "oam-network", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/oam-networks/oam-network/f9263cat-4eaa-43a0-bea4-adcf6e123456", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/oam-networks/oam-network/f9263cat-4eaa-43a0-bea4-adcf6e123456", "relationship-data": [ { "relationship-key": "cloud-region.cloud-owner", @@ -591,7 +591,7 @@ }, { "related-to": "oam-network", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/oam-networks/oam-network/b9263fab-4eaa-43a0-bea4-adcf6e999999", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/oam-networks/oam-network/b9263fab-4eaa-43a0-bea4-adcf6e999999", "relationship-data": [ { "relationship-key": "cloud-region.cloud-owner", @@ -615,7 +615,7 @@ }, { "related-to": "oam-network", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/oam-networks/oam-network/cf33dc95-c5d2-48fd-8078-fd949363f63b", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/oam-networks/oam-network/cf33dc95-c5d2-48fd-8078-fd949363f63b", "relationship-data": [ { "relationship-key": "cloud-region.cloud-owner", @@ -639,7 +639,7 @@ }, { "related-to": "availability-zone", - "related-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/availability-zones/availability-zone/mtcnj-esx-az01", + "related-link": "https://localhost:8443/aai/v9/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/availability-zones/availability-zone/mtcnj-esx-az01", "relationship-data": [ { "relationship-key": "cloud-region.cloud-owner", diff --git a/common/src/test/resources/__files/aai/resources/service-instance-pathed-query.json b/common/src/test/resources/__files/aai/resources/service-instance-pathed-query.json index 6ec513e4bb..0fa9515820 100644 --- a/common/src/test/resources/__files/aai/resources/service-instance-pathed-query.json +++ b/common/src/test/resources/__files/aai/resources/service-instance-pathed-query.json @@ -2,7 +2,7 @@ "results": [ { "resource-type": "service-instance", - "resource-link": "https://aai-conexus-e2e.test.att.com:8443/aai/v9/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3" + "resource-link": "https://localhost:8443/aai/v9/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3" } ] } \ No newline at end of file diff --git a/common/src/test/resources/__files/grm/endpoints.json b/common/src/test/resources/__files/grm/endpoints.json index 20947540b4..7e92c21c9e 100644 --- a/common/src/test/resources/__files/grm/endpoints.json +++ b/common/src/test/resources/__files/grm/endpoints.json @@ -7,7 +7,7 @@ "minor": 0, "patch": "0" }, - "hostAddress": "135.144.120.218", + "hostAddress": "192.168.120.218", "listenPort": "32004", "latitude": "37.7022", "longitude": "121.9358", @@ -54,7 +54,7 @@ "minor": 0, "patch": "0" }, - "hostAddress": "135.144.120.22", + "hostAddress": "192.168.120.22", "listenPort": "32004", "latitude": "1.0", "longitude": "1.0", @@ -101,7 +101,7 @@ "minor": 0, "patch": "0" }, - "hostAddress": "135.144.120.218", + "hostAddress": "192.168.120.218", "listenPort": "32002", "latitude": "1.0", "longitude": "1.0", diff --git a/common/src/test/resources/dmaap.properties b/common/src/test/resources/dmaap.properties index 8adb8e4976..7ce101996c 100644 --- a/common/src/test/resources/dmaap.properties +++ b/common/src/test/resources/dmaap.properties @@ -1,7 +1,7 @@ -sdno.health-check.dmaap.username=m04768@mso.ecomp.att.com +sdno.health-check.dmaap.username=testuser sdno.health-check.dmaap.password=eHQ1cUJrOUc sdno.health-check.dmaap.subscriber.topic=com.att.sdno.test-health-diagnostic-v02 sdno.health-check.dmaap.publisher.topic=com.att.sdno.test-health-diagnostic-v02 -ruby.create-ticket-request.dmaap.username=m04768@mso.ecomp.att.com +ruby.create-ticket-request.dmaap.username=testuser ruby.create-ticket-request.dmaap.password=eHQ1cUJrOUc ruby.create-ticket-request.publisher.topic=com.att.pdas.st1.msoCMFallout-v1 \ No newline at end of file diff --git a/common/src/test/resources/logback-test.xml b/common/src/test/resources/logback-test.xml index b1888ac986..c4248bf985 100644 --- a/common/src/test/resources/logback-test.xml +++ b/common/src/test/resources/logback-test.xml @@ -21,6 +21,7 @@ + @@ -44,15 +45,8 @@ - - - - - - ${defaultPattern} - - + @@ -148,24 +142,35 @@ true - + + + %d{HH:mm:ss.SSS} [%thread] |%X{RequestId}| %-5level + %logger{1024} - %msg%n + + + + - - + + - - + + + - + - - + + + + - + + \ No newline at end of file diff --git a/common/src/test/resources/mso-bad.json b/common/src/test/resources/mso-bad.json index 57b271459e..1aaea50042 100644 --- a/common/src/test/resources/mso-bad.json +++ b/common/src/test/resources/mso-bad.json @@ -1,20 +1,20 @@ { - "asdc-connections":{, - "asdc-controller1":{ - "asdcUser": "user1", - "asdcConsumerGroup": "consumer1", - "asdcConsumerId": "consumer1", - "asdcEnvironmentName": "PROD", - "asdcAddress": "localhost:8443", - "asdcPassword": "1c551b8b5ab91fcd5a0907b11c304199" - }, - "asdc-controller2":{ - "asdcUser": "user2", - "asdcConsumerGroup": "consumer2", - "asdcConsumerId": "consumer2", - "asdcEnvironmentName": "E2E", - "asdcAddress": "localhost:8443", - "asdcPassword": "1c551b8b5ab91fcd5a0907b11c304199" - } - } -} + "asdc-connections": { + "asdc-controller1": { + "asdcUser": "user1", + "asdcConsumerGroup": "consumer1", + "asdcConsumerId": "consumer1", + "asdcEnvironmentName": "PROD", + "asdcAddress": "localhost:8443", + "asdcPassword": "1c551b8b5ab91fcd5a0907b11c304199" + }, + "asdc-controller2": { + "asdcUser": "user2", + "asdcConsumerGroup": "consumer2", + "asdcConsumerId": "consumer2", + "asdcEnvironmentName": "E2E", + "asdcAddress": "localhost:8443", + "asdcPassword": "1c551b8b5ab91fcd5a0907b11c304199" + } + } +} \ No newline at end of file diff --git a/common/src/test/resources/org/onap/so/client/ruby/create-ticket/create-ticket-request.json b/common/src/test/resources/org/onap/so/client/ruby/create-ticket/create-ticket-request.json new file mode 100644 index 0000000000..e388d3e9ad --- /dev/null +++ b/common/src/test/resources/org/onap/so/client/ruby/create-ticket/create-ticket-request.json @@ -0,0 +1,15 @@ +{ + "event": { + "msoRequest": { + "requestClientName": "MSO", + "requestId": "abc123", + "requestTime": "test-time", + "sourceName": "source-name", + "reason": "reason", + "action": "Create Ticket", + "workflowId": "work-flow-Id", + "notification": "notification" + } +} +} + diff --git a/common/src/test/resources/org/onap/so/client/sdno/health-check/custom-lport-mirror-post-check-request.json b/common/src/test/resources/org/onap/so/client/sdno/health-check/custom-lport-mirror-post-check-request.json new file mode 100644 index 0000000000..2c46b5a8cb --- /dev/null +++ b/common/src/test/resources/org/onap/so/client/sdno/health-check/custom-lport-mirror-post-check-request.json @@ -0,0 +1,27 @@ +{ + "body": { + "input": { + "request-hd-custom": { + "request-client-name": "MSO", + "request-user-id": "test-user", + "request-id": "test-request-id", + "health-diagnostic-code": "VROUTER000004", + "operation-type": "lport_mirroring_check", + "send-detailed-cmd-response": "false", + "aai-param-list": [ + { + "key": "configuration-id", + "value": "test-configuration-id" + }, + { + "key": "interface-id", + "value": "test-interface-id" + } + ] + } + } + }, + "operation": "health-diagnostic-custom", + "nodeLoc": "test-clli", + "nodeType": "VROUTER" +} \ No newline at end of file diff --git a/common/src/test/resources/org/onap/so/client/sdno/health-check/custom-lport-mirror-pre-check-request.json b/common/src/test/resources/org/onap/so/client/sdno/health-check/custom-lport-mirror-pre-check-request.json new file mode 100644 index 0000000000..bf168b0028 --- /dev/null +++ b/common/src/test/resources/org/onap/so/client/sdno/health-check/custom-lport-mirror-pre-check-request.json @@ -0,0 +1,27 @@ +{ + "body": { + "input": { + "request-hd-custom": { + "request-client-name": "MSO", + "request-user-id": "test-user", + "request-id": "test-request-id", + "health-diagnostic-code": "VROUTER000003", + "operation-type": "lport_mirroring_check", + "send-detailed-cmd-response": "false", + "aai-param-list": [ + { + "key": "configuration-id", + "value": "test-configuration-id" + }, + { + "key": "interface-id", + "value": "test-interface-id" + } + ] + } + } + }, + "operation": "health-diagnostic-custom", + "nodeLoc": "test-clli", + "nodeType": "VROUTER" +} \ No newline at end of file diff --git a/common/src/test/resources/org/onap/so/client/sdno/health-check/custom-port-mirror-post-check-request.json b/common/src/test/resources/org/onap/so/client/sdno/health-check/custom-port-mirror-post-check-request.json new file mode 100644 index 0000000000..89e505e7d0 --- /dev/null +++ b/common/src/test/resources/org/onap/so/client/sdno/health-check/custom-port-mirror-post-check-request.json @@ -0,0 +1,23 @@ +{ + "body": { + "input": { + "request-hd-custom": { + "request-client-name": "MSO", + "request-user-id": "test-user", + "request-id": "test-request-id", + "health-diagnostic-code": "VROUTER000004", + "operation-type": "mirroring_check", + "send-detailed-cmd-response": "false", + "aai-param-list": [ + { + "key": "configuration-id", + "value": "test-configuration-id" + } + ] + } + } + }, + "operation": "health-diagnostic-custom", + "nodeLoc": "test-clli", + "nodeType": "VROUTER" +} \ No newline at end of file diff --git a/common/src/test/resources/org/onap/so/client/sdno/health-check/custom-port-mirror-pre-check-request.json b/common/src/test/resources/org/onap/so/client/sdno/health-check/custom-port-mirror-pre-check-request.json new file mode 100644 index 0000000000..86897c8a1f --- /dev/null +++ b/common/src/test/resources/org/onap/so/client/sdno/health-check/custom-port-mirror-pre-check-request.json @@ -0,0 +1,23 @@ +{ + "body": { + "input": { + "request-hd-custom": { + "request-client-name": "MSO", + "request-user-id": "test-user", + "request-id": "test-request-id", + "health-diagnostic-code": "VROUTER000003", + "operation-type": "mirroring_check", + "send-detailed-cmd-response": "false", + "aai-param-list": [ + { + "key": "configuration-id", + "value": "test-configuration-id" + } + ] + } + } + }, + "operation": "health-diagnostic-custom", + "nodeLoc": "test-clli", + "nodeType": "VROUTER" +} diff --git a/common/src/test/resources/org/onap/so/client/sdno/output-failure.json b/common/src/test/resources/org/onap/so/client/sdno/output-failure.json new file mode 100644 index 0000000000..8cf0a820cd --- /dev/null +++ b/common/src/test/resources/org/onap/so/client/sdno/output-failure.json @@ -0,0 +1,25 @@ +{ + "body": { + "output": { + "response-hd-custom": { + "response-status": "Failure", + "cached-data": "false", + "response-interface-type": "ansible", + "response-id": "191bf423-8473-4f7c-9fbb-e5dcbb40a12b", + "remote_end_time": "2017-10-13T14:51:53.490+0000", + "response-client-name": "MSO", + "user_id": "xxxxxx", + "remote_start_time": "2017-10-13T14:51:53.173+0000", + "error-message": "my error message", + "connection-failure-msg": "SDNO was unable to connect to an Ansible REST API server; Please ensure Ansible REST server is running" + } + } + }, + "result-info": { + "code": "200", + "status": "SUCCESS", + "request-id": "xyz123", + "client-name": "MSO", + "processing-host": "sdno-sdno-mtsnjv9sdno01" + } +} \ No newline at end of file diff --git a/common/src/test/resources/org/onap/so/client/sdno/output-success.json b/common/src/test/resources/org/onap/so/client/sdno/output-success.json new file mode 100644 index 0000000000..a6794327d8 --- /dev/null +++ b/common/src/test/resources/org/onap/so/client/sdno/output-success.json @@ -0,0 +1,22 @@ +{ + "body": { + "output": { + "response-healthdiagnostic": { + "response-node-ip": "192.20.127.76", + "response-id": "xyz123", + "response-node-name": "mtvnjv9aads11", + "response-status": "Success", + "response-interface-type": "ssh", + "response-details-json": "result", + "cached-data": "false" + } + } + }, + "result-info": { + "client-name": "MSO", + "code": "200", + "processing-host": "sdno1-host01", + "request-id": "xyz123", + "status": "SUCCESS" + } +} \ No newline at end of file diff --git a/common/src/test/resources/org/onap/so/client/sdno/response.json b/common/src/test/resources/org/onap/so/client/sdno/response.json new file mode 100644 index 0000000000..2355e86938 --- /dev/null +++ b/common/src/test/resources/org/onap/so/client/sdno/response.json @@ -0,0 +1,17 @@ +{ + + "result-info": { + + "client-name": "MSO", + + "code": "202", + + "processing-host": "sdno1-host01", + + "request-id": "xyz123", + + "status": "ACCEPTED" + + } + +} \ No newline at end of file diff --git a/common/src/test/resources/org/openecomp/mso/client/ruby/create-ticket/create-ticket-request.json b/common/src/test/resources/org/openecomp/mso/client/ruby/create-ticket/create-ticket-request.json deleted file mode 100644 index e388d3e9ad..0000000000 --- a/common/src/test/resources/org/openecomp/mso/client/ruby/create-ticket/create-ticket-request.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "event": { - "msoRequest": { - "requestClientName": "MSO", - "requestId": "abc123", - "requestTime": "test-time", - "sourceName": "source-name", - "reason": "reason", - "action": "Create Ticket", - "workflowId": "work-flow-Id", - "notification": "notification" - } -} -} - diff --git a/common/src/test/resources/org/openecomp/mso/client/sdno/health-check/custom-lport-mirror-post-check-request.json b/common/src/test/resources/org/openecomp/mso/client/sdno/health-check/custom-lport-mirror-post-check-request.json deleted file mode 100644 index 8c3ca1938d..0000000000 --- a/common/src/test/resources/org/openecomp/mso/client/sdno/health-check/custom-lport-mirror-post-check-request.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "body": { - "input": { - "request-hd-custom": { - "request-client-name": "MSO", - "request-user-id": "test-user", - "request-id": "test-request-id", - "health-diagnostic-code": "VROUTER000004", - "operation-type": "lport_mirroring_check", - "aai-param-list": [ - { - "key": "configuration-id", - "value": "test-configuration-id" - }, - { - "key": "interface-id", - "value": "test-interface-id" - } - ] - } - } - }, - "operation": "health-diagnostic-custom", - "nodeLoc": "test-clli", - "nodeType": "VROUTER" -} \ No newline at end of file diff --git a/common/src/test/resources/org/openecomp/mso/client/sdno/health-check/custom-lport-mirror-pre-check-request.json b/common/src/test/resources/org/openecomp/mso/client/sdno/health-check/custom-lport-mirror-pre-check-request.json deleted file mode 100644 index 08220abe2d..0000000000 --- a/common/src/test/resources/org/openecomp/mso/client/sdno/health-check/custom-lport-mirror-pre-check-request.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "body": { - "input": { - "request-hd-custom": { - "request-client-name": "MSO", - "request-user-id": "test-user", - "request-id": "test-request-id", - "health-diagnostic-code": "VROUTER000003", - "operation-type": "lport_mirroring_check", - "aai-param-list": [ - { - "key": "configuration-id", - "value": "test-configuration-id" - }, - { - "key": "interface-id", - "value": "test-interface-id" - } - ] - } - } - }, - "operation": "health-diagnostic-custom", - "nodeLoc": "test-clli", - "nodeType": "VROUTER" -} \ No newline at end of file diff --git a/common/src/test/resources/org/openecomp/mso/client/sdno/health-check/custom-port-mirror-post-check-request.json b/common/src/test/resources/org/openecomp/mso/client/sdno/health-check/custom-port-mirror-post-check-request.json deleted file mode 100644 index 834fcc8e72..0000000000 --- a/common/src/test/resources/org/openecomp/mso/client/sdno/health-check/custom-port-mirror-post-check-request.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "body": { - "input": { - "request-hd-custom": { - "request-client-name": "MSO", - "request-user-id": "test-user", - "request-id": "test-request-id", - "health-diagnostic-code": "VROUTER000004", - "operation-type": "mirroring_check", - "aai-param-list": [ - { - "key": "configuration-id", - "value": "test-configuration-id" - } - ] - } - } - }, - "operation": "health-diagnostic-custom", - "nodeLoc": "test-clli", - "nodeType": "VROUTER" -} \ No newline at end of file diff --git a/common/src/test/resources/org/openecomp/mso/client/sdno/health-check/custom-port-mirror-pre-check-request.json b/common/src/test/resources/org/openecomp/mso/client/sdno/health-check/custom-port-mirror-pre-check-request.json deleted file mode 100644 index 19d934d291..0000000000 --- a/common/src/test/resources/org/openecomp/mso/client/sdno/health-check/custom-port-mirror-pre-check-request.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "body": { - "input": { - "request-hd-custom": { - "request-client-name": "MSO", - "request-user-id": "test-user", - "request-id": "test-request-id", - "health-diagnostic-code": "VROUTER000003", - "operation-type": "mirroring_check", - "aai-param-list": [ - { - "key": "configuration-id", - "value": "test-configuration-id" - } - ] - } - } - }, - "operation": "health-diagnostic-custom", - "nodeLoc": "test-clli", - "nodeType": "VROUTER" -} diff --git a/common/src/test/resources/org/openecomp/mso/client/sdno/output-failure.json b/common/src/test/resources/org/openecomp/mso/client/sdno/output-failure.json deleted file mode 100644 index 15160b9dd9..0000000000 --- a/common/src/test/resources/org/openecomp/mso/client/sdno/output-failure.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "body": { - "output": { - "response-hd-custom": { - "response-status": "Failure", - "cached-data": "false", - "response-interface-type": "ansible", - "response-id": "191bf423-8473-4f7c-9fbb-e5dcbb40a12b", - "remote_end_time": "2017-10-13T14:51:53.490+0000", - "response-client-name": "MSO", - "user_id": "md5621", - "remote_start_time": "2017-10-13T14:51:53.173+0000", - "error-message": "my error message", - "connection-failure-msg": "SDNO was unable to connect to an Ansible REST API server; Please ensure Ansible REST server is running" - } - } - }, - "result-info": { - "code": "200", - "status": "SUCCESS", - "request-id": "xyz123", - "client-name": "MSO", - "processing-host": "sdno-sdno-mtsnjv9sdno01" - } -} \ No newline at end of file diff --git a/common/src/test/resources/org/openecomp/mso/client/sdno/output-success.json b/common/src/test/resources/org/openecomp/mso/client/sdno/output-success.json deleted file mode 100644 index a6794327d8..0000000000 --- a/common/src/test/resources/org/openecomp/mso/client/sdno/output-success.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "body": { - "output": { - "response-healthdiagnostic": { - "response-node-ip": "192.20.127.76", - "response-id": "xyz123", - "response-node-name": "mtvnjv9aads11", - "response-status": "Success", - "response-interface-type": "ssh", - "response-details-json": "result", - "cached-data": "false" - } - } - }, - "result-info": { - "client-name": "MSO", - "code": "200", - "processing-host": "sdno1-host01", - "request-id": "xyz123", - "status": "SUCCESS" - } -} \ No newline at end of file diff --git a/common/src/test/resources/org/openecomp/mso/client/sdno/response.json b/common/src/test/resources/org/openecomp/mso/client/sdno/response.json deleted file mode 100644 index 2355e86938..0000000000 --- a/common/src/test/resources/org/openecomp/mso/client/sdno/response.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - - "result-info": { - - "client-name": "MSO", - - "code": "202", - - "processing-host": "sdno1-host01", - - "request-id": "xyz123", - - "status": "ACCEPTED" - - } - -} \ No newline at end of file -- cgit