/**
 *
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for license information.
 *
 */

package com.microsoft.rest;

import com.microsoft.rest.sample.AutoRestIntegerTestService;
import com.microsoft.rest.sample.AutoRestIntegerTestServiceImpl;
import org.junit.Assert;
import org.junit.Test;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class AutoRestIntegerTestServiceTests {
    private CountDownLatch lock = new CountDownLatch(1);

    @Test
    public void PutMaxInt() throws Exception {
        AutoRestIntegerTestService client = new AutoRestIntegerTestServiceImpl();
        client.getIntOperations().putMax32(Integer.MAX_VALUE);
    }

    @Test
    public void PutMaxIntAsync() throws Exception {
        AutoRestIntegerTestService client = new AutoRestIntegerTestServiceImpl();
        client.getIntOperations().putMax32Async(Integer.MAX_VALUE, new ServiceCallback<Void>() {
            @Override
            public void failure(ServiceException exception) {}

            @Override
            public void success(ServiceResponse<Void> response) {
                Assert.assertEquals(200, response.getResponse().getStatus());
                lock.countDown();
            }
        });
        Assert.assertTrue(lock.await(1000, TimeUnit.MILLISECONDS));
    }

    @Test
    public void GetNullInt() throws Exception {
        AutoRestIntegerTestService client = new AutoRestIntegerTestServiceImpl();
        try {
            client.getIntOperations().getNull();
            Assert.assertTrue(false);
        } catch (Exception exception) {
            // expected
            Assert.assertEquals(NullPointerException.class, exception.getClass());
        }
    }

    @Test
    public void GetNullIntAsync() throws Exception {
        AutoRestIntegerTestService client = new AutoRestIntegerTestServiceImpl();
        client.getIntOperations().getNullAsync(new ServiceCallback<Integer>() {
            @Override
            public void failure(ServiceException exception) {}

            @Override
            public void success(ServiceResponse<Integer> response) {
                Assert.assertEquals(200, response.getResponse().getStatus());
                Assert.assertNull(response.getBody());
                lock.countDown();
            }
        });
        Assert.assertTrue(lock.await(1000, TimeUnit.MILLISECONDS));
    }

    @Test
    public void GetInvalidInt() throws Exception {
        AutoRestIntegerTestService client = new AutoRestIntegerTestServiceImpl();
        try {
            client.getIntOperations().getInvalid();
            Assert.assertTrue(false);
        } catch (Exception exception) {
            Assert.assertEquals(ServiceException.class, exception.getClass());
            Assert.assertTrue(exception.getMessage().contains("Expected an int but was STRING"));
        }
    }
}

@@ -1735,19 +1735,15 @@
 als(
-NullPointer
+Service
 Exce
@@ -1770,32 +1770,120 @@
 on.getClass());%0A
+            Assert.assertTrue(exception.getMessage().contains(%22JsonMappingException%22));%0A
         %7D%0A    %7D%0A
@@ -2183,34 +2183,32 @@
 ion exception) %7B
-%7D%0A
 %0A            @Ov
@@ -2208,86 +2208,78 @@
     
-@Override%0A            public void success(ServiceResponse%3CInteger%3E response) %7B
+    Assert.assertEquals(ServiceException.class, exception.getClass());
 %0A   
@@ -2308,110 +2308,103 @@
 sert
-Equals(200, response
+True(exception
 .get
-Response().getStatus());%0A                Assert.assertNull(response.getBody
+Message().contains(%22JsonMappingException%22));%0A                lock.countDown
 ()
-)
 ;%0A  
@@ -2400,32 +2400,40 @@
 tDown();%0A       
+     %7D%0A%0A
          lock.co
@@ -2425,33 +2425,97 @@
         
-lock.countDown();
+   @Override%0A            public void success(ServiceResponse%3CInteger%3E response) %7B
 %0A       
@@ -3041,38 +3041,26 @@
 ns(%22
-Expected an int but was STRING
+JsonParseException
 %22));

Fix client runtime tests after switching to jackson