// Path: ngsi2-client/src/test/java/com/orange/ngsi2/Utils.java
// public class Utils {
// 
//     /**
//      * Common object mapper used for most tests with Java 8 support for Optional
//      */
//     public final static ObjectMapper objectMapper = new ObjectMapper().registerModule(new Jdk8Module())
//             .registerModule(new JavaTimeModule())
//             .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
// 
//     /**
//      * Load a resource as an UTF-8 string
//      * @param name name of the resource
//      * @return the content of the resource
//      */
//     public static String loadResource(String name) {
//         try {
//             URL url = Utils.class.getClassLoader().getResource(name);
//             if (url == null) {
//                 return "";
//             }
//             return new String(Files.readAllBytes(Paths.get(url.toURI())), "UTF-8");
//         } catch (Exception e) {
//             return "";
//         }
//     }
// 
// }
// 
// Path: ngsi2-client/src/main/java/com/orange/ngsi2/exception/Ngsi2Exception.java
// public class Ngsi2Exception extends RuntimeException {
// 
//     private Error error = new Error();
// 
//     /**
//      * Return specialized exception based on the HTTP status code and error
//      * @param statusCode the response code
//      * @param error the error
//      * @return the corresponding Ngsi2Exception
//      */
//     public static Ngsi2Exception fromError(int statusCode, Error error) {
//         switch (statusCode) {
//             case 409: return new ConflictingEntitiesException(error);
//             case 400: return new InvalidatedSyntaxException(error);
//             default: return new Ngsi2Exception(error);
//         }
//     }
// 
//     public Ngsi2Exception(Error error) {
//         this(error.getError(), error.getDescription().orElse(""), error.getAffectedItems().orElse(Collections.emptyList()));
//     }
// 
//     public Ngsi2Exception(String error, String description, Collection<String> affectedItems) {
//         this.error.setError(error);
//         if (description != null) {
//             this.error.setDescription(Optional.of(description));
//         } else {
//             this.error.setDescription(Optional.empty());
//         }
//         if (affectedItems != null) {
//             this.error.setAffectedItems(Optional.of(affectedItems));
//         } else {
//             this.error.setAffectedItems(Optional.empty());
//         }
//     }
// 
//     public Error getError() {
//         return error;
//     }
// 
//     public String getMessage() {
//         return error.toString();
//     }
// }


import java.net.URL;
import java.time.Instant;
import java.util.*;
import static org.junit.Assert.*;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
import static org.springframework.test.web.client.response.MockRestResponseCreators.*;
import com.orange.ngsi2.Utils;
import com.orange.ngsi2.exception.Ngsi2Exception;
import com.orange.ngsi2.model.*;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.AsyncRestTemplate;
/*
 * Copyright (C) 2016 Orange
 *
 * 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.
 *
 */

package com.orange.ngsi2.client;






/**
 * Tests for Ngsi2Client
 */
public class Ngsi2ClientTest {

    private final static String baseURL = "http://localhost:8080";

    private MockRestServiceServer mockServer;

    private Ngsi2Client ngsiClient;

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    public Ngsi2ClientTest() {
        AsyncRestTemplate asyncRestTemplate = new AsyncRestTemplate();
        //asyncRestTemplate.setMessageConverters(Collections.singletonList(new MappingJackson2HttpMessageConverter(Utils.objectMapper)));
        ngsiClient = new Ngsi2Client(asyncRestTemplate, baseURL);
        mockServer = MockRestServiceServer.createServer(asyncRestTemplate);
    }

    @Test
    public void testGetV2_ServerError() throws Exception {
// Path: ngsi2-client/src/test/java/com/orange/ngsi2/Utils.java
// public class Utils {
// 
//     /**
//      * Common object mapper used for most tests with Java 8 support for Optional
//      */
//     public final static ObjectMapper objectMapper = new ObjectMapper().registerModule(new Jdk8Module())
//             .registerModule(new JavaTimeModule())
//             .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
// 
//     /**
//      * Load a resource as an UTF-8 string
//      * @param name name of the resource
//      * @return the content of the resource
//      */
//     public static String loadResource(String name) {
//         try {
//             URL url = Utils.class.getClassLoader().getResource(name);
//             if (url == null) {
//                 return "";
//             }
//             return new String(Files.readAllBytes(Paths.get(url.toURI())), "UTF-8");
//         } catch (Exception e) {
//             return "";
//         }
//     }
// 
// }
// 
// Path: ngsi2-client/src/main/java/com/orange/ngsi2/exception/Ngsi2Exception.java
// public class Ngsi2Exception extends RuntimeException {
// 
//     private Error error = new Error();
// 
//     /**
//      * Return specialized exception based on the HTTP status code and error
//      * @param statusCode the response code
//      * @param error the error
//      * @return the corresponding Ngsi2Exception
//      */
//     public static Ngsi2Exception fromError(int statusCode, Error error) {
//         switch (statusCode) {
//             case 409: return new ConflictingEntitiesException(error);
//             case 400: return new InvalidatedSyntaxException(error);
//             default: return new Ngsi2Exception(error);
//         }
//     }
// 
//     public Ngsi2Exception(Error error) {
//         this(error.getError(), error.getDescription().orElse(""), error.getAffectedItems().orElse(Collections.emptyList()));
//     }
// 
//     public Ngsi2Exception(String error, String description, Collection<String> affectedItems) {
//         this.error.setError(error);
//         if (description != null) {
//             this.error.setDescription(Optional.of(description));
//         } else {
//             this.error.setDescription(Optional.empty());
//         }
//         if (affectedItems != null) {
//             this.error.setAffectedItems(Optional.of(affectedItems));
//         } else {
//             this.error.setAffectedItems(Optional.empty());
//         }
//     }
// 
//     public Error getError() {
//         return error;
//     }
// 
//     public String getMessage() {
//         return error.toString();
//     }
// }


// Path: ngsi2-client/src/test/java/com/orange/ngsi2/client/Ngsi2ClientTest.java
import java.net.URL;
import java.time.Instant;
import java.util.*;
import static org.junit.Assert.*;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
import static org.springframework.test.web.client.response.MockRestResponseCreators.*;
import com.orange.ngsi2.Utils;
import com.orange.ngsi2.exception.Ngsi2Exception;
import com.orange.ngsi2.model.*;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.AsyncRestTemplate;

/*
 * Copyright (C) 2016 Orange
 *
 * 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.
 *
 */

package com.orange.ngsi2.client;






/**
 * Tests for Ngsi2Client
 */
public class Ngsi2ClientTest {

    private final static String baseURL = "http://localhost:8080";

    private MockRestServiceServer mockServer;

    private Ngsi2Client ngsiClient;

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    public Ngsi2ClientTest() {
        AsyncRestTemplate asyncRestTemplate = new AsyncRestTemplate();
        //asyncRestTemplate.setMessageConverters(Collections.singletonList(new MappingJackson2HttpMessageConverter(Utils.objectMapper)));
        ngsiClient = new Ngsi2Client(asyncRestTemplate, baseURL);
        mockServer = MockRestServiceServer.createServer(asyncRestTemplate);
    }

    @Test
    public void testGetV2_ServerError() throws Exception {
        thrown.expect(Ngsi2Exception.class);