/**
 * Copyright 2014 Jordan Zimmerman
 *
 * 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 io.soabase.core.features.client;

import org.eclipse.jetty.util.thread.ShutdownThread;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class TestClientRetries
{
    private static volatile MockApplication application;

    @BeforeClass
    public static void setup() throws Exception
    {
        application = new MockApplication();
        application.run("server");
    }

    @AfterClass
    public static void tearDown()
    {
        ShutdownThread.getInstance().run();
        application = null;
    }

    @Before
    public void setupMethod() throws InterruptedException
    {
        application.getStartedLatch().await();
        application.getThrowInternalError().set(true);
        application.getCounter().set(0);
    }

    @Test
    public void testSyncRetry()
    {
        String value = application.getClient().target("http://localhost:8080/test").request().get(String.class);
        Assert.assertEquals("test", value);
        Assert.assertEquals(application.getCounter().get(), 2);
    }

    @Test
    public void testAsyncRetry() throws ExecutionException, InterruptedException
    {
        Future<String> future = application.getClient().target("http://localhost:8080/test").request().async().get(String.class);
        String value = future.get();
        Assert.assertEquals("test", value);
        Assert.assertEquals(2, application.getCounter().get());
    }
}

@@ -707,21 +707,16 @@
 it.After
-Class
 ;%0Aimport
@@ -763,38 +763,8 @@
 re;%0A
-import org.junit.BeforeClass;%0A
 impo
@@ -916,24 +916,8 @@
 ate 
-static volatile 
 Mock
@@ -953,21 +953,16 @@
  @Before
-Class
 %0A    pub
@@ -961,31 +961,24 @@
 %0A    public 
-static 
 void setup()
@@ -975,16 +975,22 @@
 id setup
+Method
 () throw
@@ -1095,108 +1095,103 @@
     
-%7D%0A%0A
     
-@AfterClass%0A    public static void tearDown
+application.getStartedLatch().await
 ()
+;
 %0A    
-%7B%0A
     
-    ShutdownThread.getInstance().run(
+application.getThrowInternalError().set(true
 );%0A 
@@ -1212,15 +1212,28 @@
 tion
- = null
+.getCounter().set(0)
 ;%0A  
@@ -1238,30 +1238,29 @@
     %7D%0A%0A    @
-Before
+After
 %0A    public 
@@ -1268,196 +1268,66 @@
 oid 
-setupMethod() throws InterruptedException%0A    %7B%0A        application.getStartedLatch().await();%0A        application.getThrowInternalError().set(true);%0A        application.getCounter().set(0
+tearDown()%0A    %7B%0A        ShutdownThread.getInstance().run(
 );%0A 

make test more resilient