unit tests - catalog-be 67/94267/2
authorTomasz Golabek <tomasz.golabek@nokia.com>
Mon, 26 Aug 2019 10:16:32 +0000 (12:16 +0200)
committerTomasz Golabek <tomasz.golabek@nokia.com>
Mon, 26 Aug 2019 11:52:52 +0000 (11:52 +0000)
Additional junit tests

Change-Id: Icc7dd508204094643c4796eaef01febd112a7869
Issue-ID: SDC-2326
Signed-off-by: Tomasz Golabek <tomasz.golabek@nokia.com>
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ActivationRequestInformation.java
catalog-be/src/main/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetector.java
catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ActivationRequestInformationTest.java [new file with mode: 0644]
catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogicTest.java [new file with mode: 0644]
catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java [new file with mode: 0644]
catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java [new file with mode: 0644]
catalog-be/src/test/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetectorTest.java

index 70ec37c..5d98006 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.openecomp.sdc.be.components.impl;
 
+import com.google.common.annotations.VisibleForTesting;
 import org.openecomp.sdc.be.model.Service;
 
 /**
@@ -30,6 +31,9 @@ public class ActivationRequestInformation {
     private String workloadContext;
     private String tenant;
 
+    @VisibleForTesting
+    ActivationRequestInformation() {}
+
     public ActivationRequestInformation(Service serviceToActivate, String workloadContext, String tenant) {
         this.serviceToActivate = serviceToActivate;
         this.workloadContext = workloadContext;
index fcca269..9e0c130 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.openecomp.sdc.be.switchover.detector;
 
+import com.google.common.annotations.VisibleForTesting;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.http.entity.ContentType;
 import org.apache.http.entity.StringEntity;
@@ -248,6 +249,11 @@ public class SwitchoverDetector {
 
     }
 
+    @VisibleForTesting
+    void setSwitchoverDetectorConfig(SwitchoverDetectorConfig switchoverDetectorConfig) {
+        this.switchoverDetectorConfig = switchoverDetectorConfig;
+    }
+
     @PostConstruct
     private void init() {
         logger.info("Enter init method of SwitchoverDetector");
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ActivationRequestInformationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ActivationRequestInformationTest.java
new file mode 100644 (file)
index 0000000..978c0a4
--- /dev/null
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.sdc.be.components.impl;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+import org.openecomp.sdc.be.model.Service;
+
+public class ActivationRequestInformationTest {
+
+    private static final String TENANT = "tenant";
+    private static final String WORKLOAD_CONTEXT = "workloadContext";
+
+    @Test
+    public void shouldHaveValidGettersAndSetters() {
+        assertThat(ActivationRequestInformation.class, hasValidGettersAndSetters());
+    }
+
+    @Test
+    public void testFullArgConstructor() {
+        Service serviceToActivate = new Service();
+        ActivationRequestInformation activationRequestInformation = new ActivationRequestInformation(serviceToActivate,
+            WORKLOAD_CONTEXT,
+            TENANT);
+        assertEquals(activationRequestInformation.getServiceToActivate(), serviceToActivate);
+        assertEquals(activationRequestInformation.getTenant(), TENANT);
+        assertEquals(activationRequestInformation.getWorkloadContext(), WORKLOAD_CONTEXT);
+    }
+}
\ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogicTest.java
new file mode 100644 (file)
index 0000000..ce5a5bc
--- /dev/null
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.sdc.be.components.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.validation.AnnotationValidator;
+import org.openecomp.sdc.be.datatypes.elements.Annotation;
+import org.openecomp.sdc.be.model.AnnotationTypeDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AnnotationBusinessLogicTest {
+    private static final String TEST = "TEST";
+
+    @Mock
+    private AnnotationTypeOperations annotationTypeOperations;
+    @Mock
+    private AnnotationValidator annotationValidator;
+    @Mock
+    private InputDefinition inputDefinition;
+    @Mock
+    private Annotation annotation;
+    @Mock
+    private AnnotationTypeDefinition dbAnnotationTypeDefinition;
+
+    @Test
+    public void checkGetter() {
+        AnnotationBusinessLogic annotationBusinessLogic = new AnnotationBusinessLogic(annotationTypeOperations,
+            annotationValidator);
+        assertEquals(annotationBusinessLogic.getAnnotationTypeOperations(), annotationTypeOperations);
+    }
+
+    @Test
+    public void shouldValidateAndMergeAnnotationsAndAssignToInput() {
+        AnnotationBusinessLogic annotationBusinessLogic = new AnnotationBusinessLogic(annotationTypeOperations,
+            annotationValidator);
+        Map<String, InputDefinition> inputs = new HashMap<>();
+        inputs.put(TEST, inputDefinition);
+        List<Annotation> annotations = new ArrayList<>();
+        annotations.add(annotation);
+        Mockito.when(inputDefinition.getAnnotations()).thenReturn(annotations);
+        Mockito.when(annotationTypeOperations.getLatestType(Mockito.any())).thenReturn(dbAnnotationTypeDefinition);
+        annotationBusinessLogic.validateAndMergeAnnotationsAndAssignToInput(inputs);
+        List<Annotation> result = inputDefinition.getAnnotations();
+        assertEquals(result.size(),1);
+    }
+}
\ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java
new file mode 100644 (file)
index 0000000..5de1f23
--- /dev/null
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.sdc.be.components.impl;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation;
+
+@RunWith(MockitoJUnitRunner.class)
+public class GroupTypeImportManagerTest {
+
+    @Mock
+    GroupTypeOperation groupTypeOperation;
+    @Mock
+    ComponentsUtils componentsUtils;
+    @Mock
+    ToscaOperationFacade toscaOperationFacade;
+    @Mock
+    CommonImportManager commonImportManager;
+    @Mock
+    private ToscaTypeImportData data;
+
+    @Test
+    public void shouldInvokeCreateElementTypes() {
+        GroupTypeImportManager groupTypeImportManager = new GroupTypeImportManager(groupTypeOperation, componentsUtils,
+            toscaOperationFacade, commonImportManager);
+        groupTypeImportManager.createGroupTypes(data);
+        Mockito.verify(commonImportManager).createElementTypes(Mockito.any(ToscaTypeImportData.class), Mockito.any(), Mockito.any());
+    }
+}
\ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java
new file mode 100644 (file)
index 0000000..0fb17c4
--- /dev/null
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.sdc.be.components.impl;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.operations.impl.RelationshipTypeOperation;
+
+@RunWith(MockitoJUnitRunner.class)
+public class RelationshipTypeImportManagerTest {
+
+    @Mock
+    private RelationshipTypeOperation relationshipTypeOperation;
+    @Mock
+    private CommonImportManager commonImportManager;
+    @Mock
+    private ComponentsUtils componentsUtils;
+
+    @Test
+    public void shouldInvokeCreateElementTypes() {
+        RelationshipTypeImportManager relationshipTypeImportManager =
+            new RelationshipTypeImportManager(relationshipTypeOperation, commonImportManager, componentsUtils);
+        relationshipTypeImportManager.createRelationshipTypes("anyYaml");
+        Mockito.verify(commonImportManager).createElementTypes(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
+
+    }
+}
\ No newline at end of file
index 5c5261b..71b4b23 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
  */
 
 package org.openecomp.sdc.be.switchover.detector;
 
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
 
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.config.Configuration.SwitchoverDetectorConfig;
+import org.openecomp.sdc.be.switchover.detector.SwitchoverDetector.SwitchoverDetectorGroup;
+import org.openecomp.sdc.be.switchover.detector.SwitchoverDetector.SwitchoverDetectorScheduledTask;
+import org.openecomp.sdc.be.switchover.detector.SwitchoverDetector.SwitchoverDetectorState;
 
+@RunWith(MockitoJUnitRunner.class)
 public class SwitchoverDetectorTest {
 
-       private SwitchoverDetector createTestSubject() {
-               return new SwitchoverDetector();
-       }
+       private static final String SITEMODE = "SITEMODE";
+       @Mock
+       private SwitchoverDetectorConfig config;
+       @Mock
+       private SwitchoverDetectorScheduledTask task;
+       @Mock
+       private ScheduledExecutorService switchoverDetectorScheduler;
 
-       
        @Test
-       public void testGetSiteMode() throws Exception {
-               SwitchoverDetector testSubject;
-               String result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getSiteMode();
+       public void shouldSwitchoverDetectorStateGotCorrectStates() {
+               assertEquals(SwitchoverDetectorState.ACTIVE.getState(), "active");
+               assertEquals(SwitchoverDetectorState.STANDBY.getState(), "standby");
+               assertEquals(SwitchoverDetectorState.UNKNOWN.getState(), "unknown");
        }
 
-       
        @Test
-       public void testSetSiteMode() throws Exception {
-               SwitchoverDetector testSubject;
-               String mode = "";
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setSiteMode(mode);
+       public void shouldSwitchoverDetectorGroupGotCorrectGroup() {
+               assertEquals(SwitchoverDetectorGroup.BE_SET.getGroup(), "beSet");
+               assertEquals(SwitchoverDetectorGroup.FE_SET.getGroup(), "feSet");
        }
 
-       
+       @Test
+       public void shouldSwitchoverDetectorSetSiteMode() {
+               SwitchoverDetector switchoverDetector = new SwitchoverDetector();
+               switchoverDetector.setSiteMode(SITEMODE);
+               assertEquals(switchoverDetector.getSiteMode(), SITEMODE);
+       }
 
+       @Test
+       public void shouldStartSwitchoverDetectorTask() {
+               SwitchoverDetector switchoverDetector = new SwitchoverDetector();
+               switchoverDetector.setSwitchoverDetectorConfig(config);
+               switchoverDetector.switchoverDetectorScheduledTask = task;
+               switchoverDetector.switchoverDetectorScheduler = switchoverDetectorScheduler;
+               switchoverDetector.startSwitchoverDetectorTask();
+               Mockito.verify(switchoverDetectorScheduler).scheduleAtFixedRate(task, 0, 60, TimeUnit.SECONDS);
+       }
 }