aboutsummaryrefslogtreecommitdiffstats
path: root/champ-service
diff options
context:
space:
mode:
authorDriptaroop Das <driptaroop.das@in.ibm.com>2019-01-21 15:07:45 +0530
committerDriptaroop Das <driptaroop.das@in.ibm.com>2019-01-21 17:17:06 +0530
commit281fe20cd52c4f65e3e45c32cbf09d0aced6ce39 (patch)
tree70ab6631e424593e21edd4fa904da7e66a03dbdd /champ-service
parent5b2cfce94077e6677da370a7480189f290b466d5 (diff)
Unit test for ChampDataService.java
Unit test for ChampDataService.java Issue-ID: AAI-2094 Change-Id: I49736e3e691836688a085a0456c49c6bf967f0a7 Signed-off-by: Driptaroop Das <driptaroop.das@in.ibm.com>
Diffstat (limited to 'champ-service')
-rw-r--r--champ-service/pom.xml32
-rw-r--r--champ-service/src/test/java/org/onap/champ/service/ChampDataServiceTest.java75
2 files changed, 107 insertions, 0 deletions
diff --git a/champ-service/pom.xml b/champ-service/pom.xml
index 503a780..0d32783 100644
--- a/champ-service/pom.xml
+++ b/champ-service/pom.xml
@@ -91,6 +91,38 @@ limitations under the License.
<dependency>
<groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.7.4</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.javassist</groupId>
+ <artifactId>javassist</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>1.7.4</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- https://mvnrepository.com/artifact/org.javassist/javassist -->
+ <dependency>
+ <groupId>org.javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <version>3.22.0-GA</version>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
<exclusions>
<exclusion>
diff --git a/champ-service/src/test/java/org/onap/champ/service/ChampDataServiceTest.java b/champ-service/src/test/java/org/onap/champ/service/ChampDataServiceTest.java
new file mode 100644
index 0000000..d471dcc
--- /dev/null
+++ b/champ-service/src/test/java/org/onap/champ/service/ChampDataServiceTest.java
@@ -0,0 +1,75 @@
+/**
+ * ============LICENSE_START==========================================
+ * org.onap.aai
+ * ===================================================================
+ * Copyright © 2019 IBM
+ * ===================================================================
+ * 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.champ.service;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.aai.champcore.ChampGraph;
+import org.onap.aai.champcore.ChampTransaction;
+import org.onap.aai.champcore.exceptions.ChampTransactionException;
+import org.onap.aai.champcore.exceptions.ChampUnmarshallingException;
+import org.onap.aai.champcore.model.ChampElement;
+import org.onap.aai.champcore.model.ChampObject;
+import org.onap.champ.exception.ChampServiceException;
+import org.onap.champ.util.ChampProperties;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.util.Optional;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.powermock.api.mockito.PowerMockito.*;
+
+
+@RunWith(PowerMockRunner.class)
+@SuppressStaticInitializationFor("org.onap.champ.util.ChampProperties")
+@PrepareForTest({ChampProperties.class, ChampObject.class, ChampElement.class})
+public class ChampDataServiceTest {
+
+ ChampDataService champDataService;
+ ChampUUIDService champUUIDService;
+ ChampGraph graphImpl;
+ ChampTransactionCache cache;
+
+ @Before
+ public void setUp() throws Exception {
+ mockStatic(ChampProperties.class);
+ when(ChampProperties.get(anyString())).thenReturn("");
+ champUUIDService = mock(ChampUUIDService.class);
+ graphImpl = mock(ChampGraph.class);
+ cache = mock(ChampTransactionCache.class);
+ champDataService = new ChampDataService(champUUIDService, graphImpl, cache);
+ }
+
+ @Test
+ public void getObject() throws ChampServiceException, ChampTransactionException, ChampUnmarshallingException {
+ ChampTransaction transaction = mock(ChampTransaction.class);
+ Optional<ChampObject> retrieved = Optional.of(mock(ChampObject.class));
+ ChampObject element = mock(ChampObject.class);
+
+ when(champUUIDService.getObjectbyUUID(anyString(), eq(transaction))).thenReturn(retrieved);
+ when(champUUIDService.populateUUIDKey(retrieved.get())).thenReturn(element);
+ assertEquals(element, champDataService.getObject("testId", Optional.of(transaction)));
+ }
+} \ No newline at end of file