Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Add compile section

...

Now, the repo details page will be shown and you can view the code in master branch from there.

Compiling

coming soon

Unit Testing

In this tutorial, we recommend to use Junit4 and Mockito for writing the junit test.

Add Dependency

Add Junit and mockito dependency in the pom.xml if they are not there.

...

Maven

Version has to be version greater or equal to 3.3.3

Ensure your maven is installed / set up as per instruction from Maven section of Setting Up Your Development Environment page.


File settings.xml

Get settings.xml file

Following instruction from Maven Example settings.xml section of Setting Up Your Development Environment page to get your setting.xml file.

Configure settings file in IntelliJ

If you are going to do compiling in your intelliJ, follow steps in this section to configure settings.xml file in your interlliJ.


If you did not make your Maven Project by default shown, do the following:

In your interlliJ, Select View -> Tool Windows -> Maven Project

Image Added

The maven project will shown on the right side of your intelliJ window.

Image Added

 Click the Maven Settings wrench to bring up the Settings window:

Image Added

Select the Override of the User settings file, add the settings.xml file full path, the Apply button will be enabled. click on Apply to apply the change.

Compile

Projects Build Order

The SDNC projects repos should be built in the following order:

  • sdnc/core
  • sdnc/adaptors
  • sdnc/northbound
  • sdnc/plugins
  • sdnc/oam


Run Maven Build

Build From Command Line

Under the directory where your clone code is, run the following command to build the project

mvn clean install -s <the settings.xml file with full path>

Build Within InterlliJ

From interlliJ Maven Projects window, find the module marked with (root), expand it by clicking on the triange on the left side or double clicking the text. It will then show two folders : Lifecycle and Plugins. Use the same way to expand the Lifecycle folder, the build options are now shown:

Image Added

To run the build, double click the Install or select install and then click on the Run Maven Build triange icon.

To do clean, double click the clean or select clean and then click on the Run Maven Build triange icon.


Tips

Skip Maven Javadoc Build

In the case, maven javadoc compliation failing which causes build process abort. To continue build the code, we need to skip the maven javadoc compilation.

From command line

add the "maven.javadoc.skip=true" in the command line build command as the following:

mvn clean install -Dmaven.javadoc.skip=true -s <the settings.xml file with full path>

From pom file

add the following property definition:

Info
iconfalse
titlePOM file property to skip Maven JAVADOC build

<properties>

<maven.javadoc.skip>true</maven.javadoc.skip>

</properties>


Unit Testing

It is recommend to use Junit4 and Mockito to write the junit tests.

Add Dependency to POM File

Add Junit and mockito dependencies as the following to the pom.xml if they are not already there.

Info
iconfalse
titleJUnit dependencies in POM file
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>

...

<groupId>org.

...

mockito</groupId>

...

<artifactId>mockito-

...

core</artifactId>

...

<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

For more information More about how to use Mockito, refer to https://www.tutorialspoint.com/mockito/.Mockito can be found from Mockito Tutorial.

Mock Class Level Attributes

Since we don't recommend to use Powermockito, however, if sometimes Sometimes you do want to set/get class level attributes to satisfy complex test code and still keep the test coverage in sonar achievable.WhiteBox is the class under package Whitebox of package org.mockito.internal.util.reflectio that could  could be used to do code reflection.

static ObjectgetInternalState(Object target, String field) 
static voidsetInternalState(Object target, String field, Object value) 

Issue of Using

...

PowerMockito

There are multiple advantages of using Powermock PowerMockito to easily write the junit test, but it does break the design of the code and even sometimes, the written Junit doesn't contain any real test value.

Another reason is that there is compatibility issue between PowerMock and Jacoco which leads to the 0% test coverage in sonar.

The issues is that Jacoco does not like PowerMock instrumentation. Here is a detail explanation: https://github.com/powermock/powermock/wiki/Code-coverage-with-JaCoCo

Reference link:

.

However, we don't recommend to use Powermockito, due to the issue of Jacoco is not compatible with PowerMockito.https://static.javadoc.io/org.mockito/mockito-core/2.0.10-beta/org/mockito/internal/util/reflection/Whitebox.html


Commiting Code

Install git-review

...

  • If the verify jenkins build is passed for your review
    • If it is passed, ONAP Jobbuilder will add a +1 to the Verified field in your review.
  • If there's any comments in your review
    • the comments details can be view from the History section by clicking on the description or Expand All button
  • If your review has been merged
    • If your review is merged or in process to be merged, you will see in the Code-Review field, you have a +2 from one of the committer you have added in your Reviewers.


Tips

How to Change the Comments in a Review

...