Commit 60b3e952 authored by Nikolaos Kyriakoulis's avatar Nikolaos Kyriakoulis Committed by Christos Tranoris
Browse files

Fixed Unit tests for TMF API

parent 68f668eb
Loading
Loading
Loading
Loading
+8 −3
Original line number Original line Diff line number Diff line
@@ -5,6 +5,7 @@ import java.io.InputStream;


import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;


/**
/**
 * @author ctranoris
 * @author ctranoris
@@ -12,27 +13,31 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 */
 */
public class JsonUtils {
public class JsonUtils {


	static byte[] toJson(Object object) throws IOException {
	public static byte[] toJson(Object object) throws IOException {
		ObjectMapper mapper = new ObjectMapper();
		ObjectMapper mapper = new ObjectMapper();
		mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
		mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
		mapper.registerModule(new JavaTimeModule());
		return mapper.writeValueAsBytes(object);
		return mapper.writeValueAsBytes(object);
	}
	}


	static String toJsonString(Object object) throws IOException {
	public static String toJsonString(Object object) throws IOException {
		ObjectMapper mapper = new ObjectMapper();
		ObjectMapper mapper = new ObjectMapper();
		mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
		mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
		mapper.registerModule(new JavaTimeModule());
		return mapper.writeValueAsString(object);
		return mapper.writeValueAsString(object);
	}
	}


	public static <T> T toJsonObj(String content, Class<T> valueType) throws IOException {
	public static <T> T toJsonObj(String content, Class<T> valueType) throws IOException {
		ObjectMapper mapper = new ObjectMapper();
		ObjectMapper mapper = new ObjectMapper();
		mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
		mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
		mapper.registerModule(new JavaTimeModule());
		return mapper.readValue(content, valueType);
		return mapper.readValue(content, valueType);
	}
	}


	static <T> T toJsonObj(InputStream content, Class<T> valueType) throws IOException {
	public static <T> T toJsonObj(InputStream content, Class<T> valueType) throws IOException {
		ObjectMapper mapper = new ObjectMapper();
		ObjectMapper mapper = new ObjectMapper();
		mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
		mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
		mapper.registerModule(new JavaTimeModule());
		return mapper.readValue(content, valueType);
		return mapper.readValue(content, valueType);
	}
	}


+2 −2
Original line number Original line Diff line number Diff line
@@ -416,7 +416,7 @@ public class ResourceRepoService {
    if (resourceCharacteristicChanged) {
    if (resourceCharacteristicChanged) {
      Note n = new Note();
      Note n = new Note();
      n.setText("Resource characteristics changed : " + charsChanged);
      n.setText("Resource characteristics changed : " + charsChanged);
      n.setAuthor( "RI6398-API" );
      n.setAuthor( "RI639-API" );
      n.setDate( OffsetDateTime.now(ZoneOffset.UTC).toString() );
      n.setDate( OffsetDateTime.now(ZoneOffset.UTC).toString() );
      resource.addNoteItem( n );                  
      resource.addNoteItem( n );                  
      
      
@@ -425,7 +425,7 @@ public class ResourceRepoService {
    if (resourceStateChanged) {
    if (resourceStateChanged) {
      Note n = new Note();
      Note n = new Note();
      n.setText("Resource resourceStateChanged changed to " + resource.getResourceStatus().toString() );
      n.setText("Resource resourceStateChanged changed to " + resource.getResourceStatus().toString() );
      n.setAuthor( "RI6398-API" );
      n.setAuthor( "RI639-API" );
      n.setDate( OffsetDateTime.now(ZoneOffset.UTC).toString() );
      n.setDate( OffsetDateTime.now(ZoneOffset.UTC).toString() );
      resource.addNoteItem( n );                  
      resource.addNoteItem( n );                  
      
      
+3 −0
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@ import java.util.ArrayList;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.ProducerTemplate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.LogFactory;

import org.etsi.osl.tmf.OpenAPISpringBoot;
import org.etsi.osl.tmf.OpenAPISpringBoot;
import org.etsi.osl.tmf.am642.model.AffectedService;
import org.etsi.osl.tmf.am642.model.AffectedService;
import org.etsi.osl.tmf.am642.model.Alarm;
import org.etsi.osl.tmf.am642.model.Alarm;
@@ -46,6 +47,8 @@ import org.etsi.osl.tmf.am642.model.Comment;
import org.etsi.osl.tmf.am642.model.PerceivedSeverityType;
import org.etsi.osl.tmf.am642.model.PerceivedSeverityType;
import org.etsi.osl.tmf.am642.model.ProbableCauseType;
import org.etsi.osl.tmf.am642.model.ProbableCauseType;
import org.etsi.osl.tmf.am642.reposervices.AlarmRepoService;
import org.etsi.osl.tmf.am642.reposervices.AlarmRepoService;
import org.etsi.osl.tmf.JsonUtils;

import org.junit.Before;
import org.junit.Before;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
+3 −0
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@ import java.util.UUID;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.LogFactory;

import org.etsi.osl.tmf.OpenAPISpringBoot;
import org.etsi.osl.tmf.OpenAPISpringBoot;
import org.etsi.osl.tmf.cm629.model.Customer;
import org.etsi.osl.tmf.cm629.model.Customer;
import org.etsi.osl.tmf.cm629.model.CustomerCreate;
import org.etsi.osl.tmf.cm629.model.CustomerCreate;
@@ -39,6 +40,8 @@ import org.etsi.osl.tmf.cm629.service.CustomerRepoService;
import org.etsi.osl.tmf.pm632.model.ContactMedium;
import org.etsi.osl.tmf.pm632.model.ContactMedium;
import org.etsi.osl.tmf.pm632.model.MediumCharacteristic;
import org.etsi.osl.tmf.pm632.model.MediumCharacteristic;
import org.etsi.osl.tmf.prm669.model.RelatedParty;
import org.etsi.osl.tmf.prm669.model.RelatedParty;
import org.etsi.osl.tmf.JsonUtils;

import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
+0 −39
Original line number Original line Diff line number Diff line
package org.etsi.osl.services.api;

import java.io.IOException;
import java.io.InputStream;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author ctranoris
 *
 */
public class JsonUtils {

	static byte[] toJson(Object object) throws IOException {
		ObjectMapper mapper = new ObjectMapper();
		mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
		return mapper.writeValueAsBytes(object);
	}

	static String toJsonString(Object object) throws IOException {
		ObjectMapper mapper = new ObjectMapper();
		mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
		return mapper.writeValueAsString(object);
	}

	static <T> T toJsonObj(String content, Class<T> valueType) throws IOException {
		ObjectMapper mapper = new ObjectMapper();
		mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
		return mapper.readValue(content, valueType);
	}

	static <T> T toJsonObj(InputStream content, Class<T> valueType) throws IOException {
		ObjectMapper mapper = new ObjectMapper();
		mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
		return mapper.readValue(content, valueType);
	}

}
Loading