diff options
author | ToineSiebelink <toine.siebelink@est.tech> | 2020-09-30 16:11:55 +0100 |
---|---|---|
committer | ToineSiebelink <toine.siebelink@est.tech> | 2020-10-01 08:41:06 +0100 |
commit | dce3695032ff3320fc7bfee46c4e36fde6d98883 (patch) | |
tree | 8fe2a5d56d7156694ab54f46098a61456a0eafee | |
parent | 6612c79168d699190044ab1950400061c85d1be7 (diff) |
Set up Groovy & Spock Test Framework
Add basic first test (CpServiceImplSpec) for illustartion purposes
Issue-ID: CCSDK-2786
Jira Link: https://jira.onap.org/browse/CCSDK-2786
Change-Id: Ibda81289fb5c9a57474f242e26847b8464dc6b59
-rw-r--r-- | cps/cps-service/pom.xml | 25 | ||||
-rw-r--r-- | cps/cps-service/src/test/groovy/org/onap/cps/api/impl/CpServiceImplSpec.groovy | 27 | ||||
-rw-r--r-- | cps/pom.xml | 32 |
3 files changed, 82 insertions, 2 deletions
diff --git a/cps/cps-service/pom.xml b/cps/cps-service/pom.xml index e0d7ebd8e0..a59376c20f 100644 --- a/cps/cps-service/pom.xml +++ b/cps/cps-service/pom.xml @@ -30,8 +30,9 @@ </dependency>
<dependency>
+ <!-- required for processing yang data in json format -->
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-data-codec-xml</artifactId>
+ <artifactId>yang-data-codec-gson</artifactId>
<version>${org.opendaylight.yangtools.version}</version>
</dependency>
@@ -58,6 +59,26 @@ <artifactId>gson</artifactId>
</dependency>
+ <!-- T E S T D E P E N D E N C I E S -->
+
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy</artifactId>
+ <version>${version.groovy}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.spockframework</groupId>
+ <artifactId>spock-core</artifactId>
+ <version>${version.spock-core}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib-nodep</artifactId>
+ <version>3.1</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
-</project>
\ No newline at end of file +</project>
diff --git a/cps/cps-service/src/test/groovy/org/onap/cps/api/impl/CpServiceImplSpec.groovy b/cps/cps-service/src/test/groovy/org/onap/cps/api/impl/CpServiceImplSpec.groovy new file mode 100644 index 0000000000..27f7482112 --- /dev/null +++ b/cps/cps-service/src/test/groovy/org/onap/cps/api/impl/CpServiceImplSpec.groovy @@ -0,0 +1,27 @@ +package org.onap.cps.api.impl + +import org.onap.cps.spi.DataPersistencyService +import spock.lang.Specification; + + +class CpServiceImplSpec extends Specification { + + def dataPersistencyService = Mock(DataPersistencyService) + def objectUnderTest = new CpServiceImpl() + + def setup() { + // Insert mocked dependencies + objectUnderTest.dataPersistencyService = dataPersistencyService; + } + + def 'Storing a json object'() { + given: 'that the data persistency service returns an id of 123' + dataPersistencyService.storeJsonStructure(_) >> 123 + + when: 'a json structure is stored using the data persistency service' + def result = objectUnderTest.storeJsonStructure('') + + then: ' the same id is returned' + result == 123 + } +} diff --git a/cps/pom.xml b/cps/pom.xml index 7f50cb1437..5435c4a4a6 100644 --- a/cps/pom.xml +++ b/cps/pom.xml @@ -23,6 +23,8 @@ <springboot.version>2.3.3.RELEASE</springboot.version>
<oparent.version>3.1.0</oparent.version>
<org.opendaylight.yangtools.version>5.0.5</org.opendaylight.yangtools.version>
+ <version.groovy>3.0.6</version.groovy>
+ <version.spock-core>2.0-M2-groovy-3.0</version.spock-core>
</properties>
<dependencyManagement>
@@ -102,6 +104,36 @@ </dependencies>
</plugin>
+
+ <!-- Mandatory plugins for using Spock -->
+ <plugin>
+ <!-- The gmavenplus plugin is used to compile Groovy code. To learn more about this plugin,
+ visit https://github.com/groovy/GMavenPlus/wiki -->
+ <groupId>org.codehaus.gmavenplus</groupId>
+ <artifactId>gmavenplus-plugin</artifactId>
+ <version>1.9.0</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compileTests</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <!-- Required because names of spec classes don't match default Surefire patterns (`*Test` etc.) -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>3.0.0-M5</version>
+ <configuration>
+ <useFile>false</useFile>
+ <includes>
+ <include>**/*Spec.java</include>
+ <include>**/*Test.java</include> <!-- Just in case of having also "normal" JUnit tests -->
+ </includes>
+ </configuration>
+ </plugin>
+
</plugins>
</build>
|