Skip to content

Format and cleanup java source #705

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,17 @@
import ch.ivyteam.ivy.security.IUser;
import ch.ivyteam.ivy.security.user.NewUser;

public class UserCreator
{
public class UserCreator {

public static void createUsers(String prefix, int amount)
{
public static void createUsers(String prefix, int amount) {
var security = Ivy.security();
for (int i = 0; i < amount; i++)
{
if (i % 100 == 0)
{
for (int i = 0; i < amount; i++) {
if (i % 100 == 0) {
System.out.println("/" + i);
}
String userN = prefix + i;
IUser user = security.users().find(userN);
if (user == null)
{
if (user == null) {
var newUser = NewUser.create(userN)
.fullName(userN)
.password(userN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@

import java.io.Writer;

import com.axonivy.connectivity.test.GreeterPolicyData;

import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.request.IHttpResponse;

import com.axonivy.connectivity.test.GreeterPolicyData;

public class WSResponseWriter
{
public class WSResponseWriter {

public static void sendAsResponse(String message) throws Exception
{
public static void sendAsResponse(String message) throws Exception {
GreeterPolicyData data = new GreeterPolicyData();
data.setGreetResponse(message);
getHttpResponseWriter().append(message);
}

private static Writer getHttpResponseWriter() throws Exception
{
private static Writer getHttpResponseWriter() throws Exception {
IHttpResponse httpResponse = (IHttpResponse) Ivy.response();
return httpResponse.getHttpServletResponse().getWriter();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,29 @@
/**
* Tests the REST interface of the {@link com.axonivy.connectivity.rest.provider.BatchService}.
*/
public class IntegrationTestBatchService
{
public class IntegrationTestBatchService {
public static final String REST_USER = "restUser";

@Test
public void async() throws Exception
{
public void async() throws Exception {
WebTarget target = createAuthenticatedClient()
.target(EngineUrl.createRestUrl("/batch/async"))
.queryParam("blockSeconds", 1);
.target(EngineUrl.createRestUrl("/batch/async"))
.queryParam("blockSeconds", 1);
Future<Response> future = target.request().async().get();
Response asyncResponse = future.get(10, TimeUnit.SECONDS);

assertThat(asyncResponse.readEntity(String.class))
.isEqualTo("Sorry for the slow processing!");
.isEqualTo("Sorry for the slow processing!");
assertThat(asyncResponse.getHeaderString("responseThread"))
.as("annotated with @ManagedAsync: should not run in tomcat thread pool.")
.startsWith("jersey-server-managed-async-executor-");
.as("annotated with @ManagedAsync: should not run in tomcat thread pool.")
.startsWith("jersey-server-managed-async-executor-");
assertThat(asyncResponse.getHeaderString("sessionUser"))
.as("ivy context must be super save restored also in non tomcat thread pools.")
.isEqualTo(REST_USER);
.as("ivy context must be super save restored also in non tomcat thread pools.")
.isEqualTo(REST_USER);
}

@SuppressWarnings("deprecation")
private static Client createAuthenticatedClient()
{
private static Client createAuthenticatedClient() {
Client httpClient = ClientBuilder.newClient();
httpClient.register(JacksonJsonProvider.class);
httpClient.register(HttpAuthenticationFeature.basic(REST_USER, REST_USER));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@
/**
* Tests the REST interface of the {@link com.axonivy.connectivity.rest.provider.SecureService}.
*/
public class IntegrationTestChatService
{
public class IntegrationTestChatService {

@Test
public void p2p_onlineChat() throws Exception
{
public void p2p_onlineChat() throws Exception {
Future<Response> cliFuture = createAuthenticatedClient().target(chatResource).request().async().get();

Response sentResp = postSync(chatResource + "/" + REST_USER, REST_USER, "hey, how are you?");
Expand All @@ -57,31 +55,28 @@ public void p2p_onlineChat() throws Exception
}

@Test
public void p2p_offlineChat() throws Exception
{
public void p2p_offlineChat() throws Exception {
Response sentResp = postSync(chatResource + "/" + REST_USER, REST_USER, "can you send me the files?");
assertThat(sentResp.getStatusInfo().getFamily()).isEqualTo(Family.SUCCESSFUL);

Response cliResponse = createAuthenticatedClient()
.target(chatResource).request()
.async().get().get(2, TimeUnit.SECONDS);
.target(chatResource).request()
.async().get().get(2, TimeUnit.SECONDS);
assertThat(cliResponse.getStatusInfo().getFamily()).isEqualTo(Family.SUCCESSFUL);

List<ChatMessage> messages = cliResponse.readEntity(MSG_LIST);
assertThat(messages.get(0).message).isEqualTo("can you send me the files?");
}

private Response postSync(String resource, String as, String message)
{
private Response postSync(String resource, String as, String message) {
return createClient().register(HttpAuthenticationFeature.basic(as, as))
.target(resource).request()
.header(CsrfProtectionFilter.HEADER_NAME, "ivy")
.post(Entity.entity(message, MediaType.TEXT_PLAIN));
.target(resource).request()
.header(CsrfProtectionFilter.HEADER_NAME, "ivy")
.post(Entity.entity(message, MediaType.TEXT_PLAIN));
}

@Test
public void highLoad() throws Throwable
{
public void highLoad() throws Throwable {
int clientCount = 50;// 2000; // feel free to push limits harder - but for
// CI we relax.

Expand All @@ -95,8 +90,8 @@ public void highLoad() throws Throwable

System.out.print("Waiting for " + clientCount + " listening clients...");
Awaitility.await().timeout(30, TimeUnit.SECONDS)
.pollInterval(2, TimeUnit.SECONDS)
.until(() -> countConnectedClients().equals(clientCount));
.pollInterval(2, TimeUnit.SECONDS)
.until(() -> countConnectedClients().equals(clientCount));
System.out.println(" DONE!");

Response sentResp = postSync(chatResource, "theBoss", "hello world :-)");
Expand All @@ -112,57 +107,48 @@ public void highLoad() throws Throwable
System.out.println(" DONE!");
}

private void testClients(List<AsyncChatClient> clients) throws Throwable
{
for (int i = 0; i < clients.size(); i++)
{
if (i % 100 == 0)
{
private void testClients(List<AsyncChatClient> clients) throws Throwable {
for (int i = 0; i < clients.size(); i++) {
if (i % 100 == 0) {
System.out.print(i);
}
assertSuccess(clients.get(i));
}
}

private void createTestUsers(int clientCount) throws IOException, ClientProtocolException
{
private void createTestUsers(int clientCount) throws IOException, ClientProtocolException {
String createUsers = "1675F33D16FB90A4";
String url = EngineUrl.createProcessUrl("/connectivity-demos-test/" + createUsers +
"/createTestUsers.ivp?prefix=test&amount=" + clientCount);
"/createTestUsers.ivp?prefix=test&amount=" + clientCount);
CloseableHttpClient client = HttpClients.createDefault();
client.execute(new HttpGet(url));
}

private Integer countConnectedClients()
{
private Integer countConnectedClients() {
Integer cliCount = silentClient().target(chatResource + "/count").request().get()
.readEntity(Integer.class);
.readEntity(Integer.class);
System.out.print("..." + cliCount);
return cliCount;
}

private void assertSuccess(AsyncChatClient client) throws Throwable
{
private void assertSuccess(AsyncChatClient client) throws Throwable {
Throwable error = client.error.get();
if (error != null)
{
if (error != null) {
throw error;
}

Awaitility.await().timeout(2, TimeUnit.SECONDS)
.pollInterval(2, TimeUnit.MILLISECONDS)
.untilAtomic(client.messages, IsNull.notNullValue());
.pollInterval(2, TimeUnit.MILLISECONDS)
.untilAtomic(client.messages, IsNull.notNullValue());

List<ChatMessage> msgs = client.messages.get();
assertThat(msgs).hasSize(1);
assertThat(msgs.get(0).message).endsWith("hello world :-)");
}

private List<AsyncChatClient> createConcurrentClients(int amount)
{
private List<AsyncChatClient> createConcurrentClients(int amount) {
List<AsyncChatClient> clients = new ArrayList<>();
for (int i = 0; i < amount; i++)
{
for (int i = 0; i < amount; i++) {
clients.add(new AsyncChatClient("test" + i));
}
return clients;
Expand All @@ -172,61 +158,46 @@ private List<AsyncChatClient> createConcurrentClients(int amount)

public static final String REST_USER = "restUser";

private static final GenericType<List<ChatMessage>> MSG_LIST = new GenericType<List<ChatMessage>>()
{
};
private static final GenericType<List<ChatMessage>> MSG_LIST = new GenericType<>(){};

private static Client createAuthenticatedClient()
{
private static Client createAuthenticatedClient() {
return createClient().register(HttpAuthenticationFeature.basic(REST_USER, REST_USER));
}

@SuppressWarnings("deprecation")
private static Client createClient()
{
private static Client createClient() {
return silentClient().register(new org.glassfish.jersey.filter.LoggingFilter());
}

private static Client silentClient()
{
private static Client silentClient() {
return ClientBuilder.newClient().register(JacksonJsonProvider.class);
}

private static class AsyncChatClient implements InvocationCallback<List<ChatMessage>>
{
private static class AsyncChatClient implements InvocationCallback<List<ChatMessage>> {
public final AtomicReference<List<ChatMessage>> messages = new AtomicReference<>(null);
public final AtomicReference<Throwable> error = new AtomicReference<>(null);
public final String user;

public AsyncChatClient(String user)
{
public AsyncChatClient(String user) {
this.user = user;
}

@Override
public void completed(List<ChatMessage> response)
{
public void completed(List<ChatMessage> response) {
messages.set(response);
}

@Override
public void failed(Throwable throwable)
{
public void failed(Throwable throwable) {
error.set(throwable);
}

public Callable<Void> toCall(String resource)
{
return new Callable<Void>()
{
@Override
public Void call() throws Exception
{
Client client = silentClient().register(HttpAuthenticationFeature.basic(user, user));
client.target(resource).request().async().get(AsyncChatClient.this);
return null;
}
};
public Callable<Void> toCall(String resource) {
return () -> {
Client client = silentClient().register(HttpAuthenticationFeature.basic(user, user));
client.target(resource).request().async().get(AsyncChatClient.this);
return null;
};
}
}

Expand Down
Loading
Loading