Skip to content

Commit

Permalink
remove util class and duplicated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAure committed Jul 12, 2023
1 parent c43e337 commit f803b8f
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 294 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package ee.jakarta.tck.concurrent.api.ManagedThreadFactory;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.jboss.arquillian.container.test.api.Deployment;
Expand Down Expand Up @@ -49,6 +50,20 @@ public static WebArchive createDeployment() {

@Resource(lookup = TestConstants.DefaultManagedThreadFactory)
public ManagedThreadFactory threadFactory;

/*
* @testName: isShutdown
*
* @assertion_ids: CONCURRENCY:JAVADOC:20;CONCURRENCY:SPEC:99.1;
*
* @test_Strategy: Lookup default ManagedThreadFactory object and create new
* thread. Check return value of method isShutdown of new thread.
*/
@Test
public void isShutdown() {
ManageableThread m = (ManageableThread) threadFactory.newThread(new CounterRunnableTask());
assertFalse(m.isShutdown());
}


/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@
package ee.jakarta.tck.concurrent.api.Trigger;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.Date;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.shrinkwrap.api.ShrinkWrap;
Expand All @@ -40,7 +34,6 @@
import ee.jakarta.tck.concurrent.common.tasks.CommonTasks;
import ee.jakarta.tck.concurrent.common.tasks.CommonTriggers;
import ee.jakarta.tck.concurrent.framework.TestConstants;
import ee.jakarta.tck.concurrent.framework.TestUtil;
import ee.jakarta.tck.concurrent.framework.junit.anno.Common;
import ee.jakarta.tck.concurrent.framework.junit.anno.Common.PACKAGE;
import ee.jakarta.tck.concurrent.framework.junit.anno.Web;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.time.Duration;

import ee.jakarta.tck.concurrent.framework.TestUtil;
import ee.jakarta.tck.concurrent.framework.junit.extensions.Wait;

public class CounterRunnableTask implements Runnable, WorkInterface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.concurrent.Callable;

import ee.jakarta.tck.concurrent.framework.TestConstants;
import ee.jakarta.tck.concurrent.framework.TestUtil;
import ee.jakarta.tck.concurrent.framework.junit.extensions.Wait;

public class CommonTasks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Enumeration;
import java.util.Properties;

/**
Expand Down Expand Up @@ -106,7 +110,7 @@ private String assertSuccessfulURLResponse(URL url, Properties props) {
if(withProps) {
con.setRequestMethod("POST");
try( DataOutputStream wr = new DataOutputStream( con.getOutputStream())){
wr.writeBytes( TestUtil.toEncodedString(props) );
wr.writeBytes( toEncodedString(props) );
}

} else {
Expand Down Expand Up @@ -140,6 +144,23 @@ private String assertSuccessfulURLResponse(URL url, Properties props) {
}
}

static String toEncodedString(Properties args) throws UnsupportedEncodingException {
StringBuffer buf = new StringBuffer();
Enumeration<?> names = args.propertyNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
String value = args.getProperty(name);

buf.append(URLEncoder.encode(name, StandardCharsets.UTF_8.name()))
.append("=")
.append(URLEncoder.encode(value, StandardCharsets.UTF_8.name()));

if (names.hasMoreElements())
buf.append("&");
}
return buf.toString();
}

/**
* Override this method to return the servlet path for the suite of tests.
* Used for the runTest() methods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@
*/
package ee.jakarta.tck.concurrent.framework;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLConnection;
import java.util.Properties;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
Expand All @@ -37,6 +43,8 @@ public class TestServlet extends HttpServlet {

private static final TestLogger log = TestLogger.get(TestServlet.class);

public static final String nl = System.lineSeparator();

private boolean runBeforeClass = true;

public static final String SUCCESS = "SUCCESS";
Expand Down Expand Up @@ -141,4 +149,54 @@ protected void invokeTest(String method, HttpServletRequest request, HttpServlet
+ " with any of the following signatures: " + method + "(HttpServletRequest, HttpServletResponse) "
+ method + "()");
}

/**
* HTTP convenience method for servlets to get a response from another servlet.
* Test clients should extend the {@link TestClient} class that has its own HTTP methods.
*
* @param con - the URLConnection
* @return String - response body
* @throws IOException
*/
public static String getResponse(URLConnection con) throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()))) {

StringBuffer response = new StringBuffer();

String line;
while ((line = br.readLine()) != null) {
response.append(line).append(nl);
}

return response.toString();
}
}

/**
* HTTP convenience method for servlets to create a URLConnection and post properties
* to that connection.
*
* Test clients should extend the {@link TestClient} class that has its own HTTP methods.
*
* @param url - the URL to open a connection to
* @param props - the properties to put into the connection input stream
*
* @return the connection for further testing
* @throws IOException
*/
public static URLConnection sendPostData(URL url, Properties props) throws IOException {
log.info("Opening url connection to: " + url.toString());
URLConnection urlConn = url.openConnection();
// Begin POST of properties to SERVLET
String argString = TestClient.toEncodedString(props);
urlConn.setDoOutput(true);
urlConn.setDoInput(true);
urlConn.setUseCaches(false);
DataOutputStream out = new DataOutputStream(urlConn.getOutputStream());
out.writeBytes(argString);
out.flush();
out.close();
// End POST
return urlConn;
}
}
112 changes: 0 additions & 112 deletions tck/src/main/java/ee/jakarta/tck/concurrent/framework/TestUtil.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;

import ee.jakarta.tck.concurrent.framework.TestUtil;
import ee.jakarta.tck.concurrent.framework.TestServlet;
import ee.jakarta.tck.concurrent.framework.junit.anno.Common;
import ee.jakarta.tck.concurrent.framework.junit.extensions.AssertionExtension;

Expand All @@ -39,7 +39,7 @@ public class TCKFrameworkAppender implements AuxiliaryArchiveAppender {

private static final Logger log = Logger.getLogger(TCKFrameworkAppender.class.getCanonicalName());

private static final Package utilPackage = TestUtil.class.getPackage();
private static final Package utilPackage = TestServlet.class.getPackage();
private static final Package annoPackage = Common.class.getPackage();
private static final Package extePackage = AssertionExtension.class.getPackage();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package ee.jakarta.tck.concurrent.framework.junit.extensions;

import static org.junit.jupiter.api.Assertions.fail;

import java.util.Iterator;

/**
Expand Down
Loading

0 comments on commit f803b8f

Please sign in to comment.