aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ActivationRequestInformation.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetector.java6
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ActivationRequestInformationTest.java49
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogicTest.java75
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java53
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java48
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetectorTest.java65
7 files changed, 279 insertions, 21 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ActivationRequestInformation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ActivationRequestInformation.java
index 70ec37ce48..5d98006dec 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ActivationRequestInformation.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ActivationRequestInformation.java
@@ -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;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetector.java b/catalog-be/src/main/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetector.java
index fcca2697c2..9e0c130b21 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetector.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetector.java
@@ -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
index 0000000000..978c0a4796
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ActivationRequestInformationTest.java
@@ -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
index 0000000000..ce5a5bc352
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogicTest.java
@@ -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
index 0000000000..5de1f23181
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java
@@ -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
index 0000000000..0fb17c4c87
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java
@@ -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
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetectorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetectorTest.java
index 5c5261bc23..71b4b237a0 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetectorTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetectorTest.java
@@ -16,41 +16,64 @@
* 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);
+ }
}