Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c422241
add jacoco plugin
YBushi Jun 8, 2024
9aa0841
Create .gitattributes
YBushi Jun 8, 2024
759e955
Normalize all line endings to LF
YBushi Jun 8, 2024
56f0a96
Normalize all line endings to LF
YBushi Jun 8, 2024
f389b08
Revert "Normalize all line endings to LF"
YBushi Jun 8, 2024
e84040a
Revert "Normalize all line endings to LF"
YBushi Jun 8, 2024
49d6ffe
.picked functions to cover
YBushi Jun 9, 2024
ac025a4
added readme which we should use for the report of our assignment
YBushi Jun 9, 2024
22ff531
Update README.md
YBushi Jun 9, 2024
30ddaf0
.added my 2 methods that I covered into the report
YBushi Jun 9, 2024
8385a7b
.disabled checkstyles so its easier to code without having to worry a…
YBushi Jun 9, 2024
99b6a14
Update README.md - Jayran 2 functions
jayran-d Jun 9, 2024
d865301
Update README.md
nikola20145 Jun 9, 2024
0983313
.disable programming mistake detector
YBushi Jun 10, 2024
c97456e
.added before/after coverage
YBushi Jun 10, 2024
8fa3da5
Update README.md
nikola20145 Jun 10, 2024
0976235
Update README.md
nikola20145 Jun 10, 2024
3884fad
Update README.md
nikola20145 Jun 10, 2024
f959b03
Update README.md
nikola20145 Jun 10, 2024
322bdc7
Update README.md
nikola20145 Jun 10, 2024
95bd2b6
Update README.md
nikola20145 Jun 10, 2024
e4efa5c
Update NingHttpClient.java
nikola20145 Jun 10, 2024
3015c50
Update pom.xml
nikola20145 Jun 10, 2024
31761ff
Update settings.json
nikola20145 Jun 10, 2024
de3bbe5
Update ArmeriaHttpClient.java
nikola20145 Jun 10, 2024
b7de5fe
Last updates for Assignment 1
nikola20145 Jun 18, 2024
d040a99
Changing Armeria file to the same as it is in master
nikola20145 Jun 20, 2024
292d26f
Update NingHttpClient.java
nikola20145 Jun 20, 2024
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
Prev Previous commit
Next Next commit
Last updates for Assignment 1
Facebook Error Response 3.3 and 3.4 as well as modifications for NingHttpClientTest for 3.3 and 3.4 that include changing the pom.xml file inside Ning
  • Loading branch information
nikola20145 committed Jun 18, 2024
commit b7de5fece3f9561aed09a9fef108c4bf4398ef49
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.github.scribejava.core.model.Response;
import java.io.IOException;
import java.util.Objects;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* non standard Facebook replace for {@link com.github.scribejava.core.model.OAuth2AccessTokenErrorResponse}
*
Expand All @@ -25,6 +27,32 @@ public class FacebookAccessTokenErrorResponse extends OAuthResponseException {
private final int codeInt;
private final String fbtraceId;

// Branch coverage data structure Nikola
private static final ConcurrentHashMap<String, AtomicBoolean> branchCoverage = new ConcurrentHashMap<>();

static {
branchCoverage.put("FacebookAccessTokenErrorResponse.equals.branch_1", new AtomicBoolean(false));
branchCoverage.put("FacebookAccessTokenErrorResponse.equals.branch_2", new AtomicBoolean(false));
branchCoverage.put("FacebookAccessTokenErrorResponse.equals.branch_3", new AtomicBoolean(false));
branchCoverage.put("FacebookAccessTokenErrorResponse.equals.branch_4", new AtomicBoolean(false));
branchCoverage.put("FacebookAccessTokenErrorResponse.equals.branch_5", new AtomicBoolean(false));
branchCoverage.put("FacebookAccessTokenErrorResponse.equals.branch_6", new AtomicBoolean(false));
branchCoverage.put("FacebookAccessTokenErrorResponse.equals.branch_7", new AtomicBoolean(false));


Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
synchronized (System.out) {
System.out.println("FacebookAccessTokenErrorResponse equals method coverage:");
for (Map.Entry<String, AtomicBoolean> entry : branchCoverage.entrySet()) {
System.out.println(entry.getKey() + ": " + (entry.getValue().get() ? "Taken" : "Not taken"));
}
}
}
}));
}

public FacebookAccessTokenErrorResponse(String errorMessage, String type, int code, String fbtraceId,
Response response)
throws IOException {
Expand Down Expand Up @@ -61,33 +89,39 @@ public int hashCode() {
return hash;
}

// branch coverage Nikola
@Override
public boolean equals(Object obj) {
if (this == obj) {
branchCoverage.get("FacebookAccessTokenErrorResponse.equals.branch_1").set(true);
return true;
}
if (obj == null) {
branchCoverage.get("FacebookAccessTokenErrorResponse.equals.branch_2").set(true);
return false;
}
if (getClass() != obj.getClass()) {
branchCoverage.get("FacebookAccessTokenErrorResponse.equals.branch_3").set(true);
return false;
}
if (!super.equals(obj)) {
FacebookAccessTokenErrorResponse other = (FacebookAccessTokenErrorResponse) obj;
if (!Objects.equals(errorMessage, other.errorMessage)) {
branchCoverage.get("FacebookAccessTokenErrorResponse.equals.branch_4").set(true);
return false;
}

final FacebookAccessTokenErrorResponse other = (FacebookAccessTokenErrorResponse) obj;

if (!Objects.equals(errorMessage, other.getErrorMessage())) {
if (!Objects.equals(type, other.type)) {
branchCoverage.get("FacebookAccessTokenErrorResponse.equals.branch_5").set(true);
return false;
}
if (!Objects.equals(type, other.getType())) {
if (codeInt != other.codeInt) {
branchCoverage.get("FacebookAccessTokenErrorResponse.equals.branch_6").set(true);
return false;
}
if (codeInt != other.getCodeInt()) {
if (!Objects.equals(fbtraceId, other.fbtraceId)) {
branchCoverage.get("FacebookAccessTokenErrorResponse.equals.branch_7").set(true);
return false;
}
return Objects.equals(fbtraceId, other.getFbtraceId());
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.github.scribejava.apis.facebook;

import com.github.scribejava.core.model.Response;
import java.io.IOException;
import java.util.Collections;
import static org.junit.Assert.*;
import org.junit.Test;

public class FacebookAccessTokenErrorResponseTest {

@Test
public void testEquals_Self() throws IOException {
Response response = new Response(200, "OK", Collections.<String, String>emptyMap(), "Body content here");
FacebookAccessTokenErrorResponse errorResponse = new FacebookAccessTokenErrorResponse(
"Message", "Type", 100, "TraceID", response);

assertTrue("Should return true when comparing to itself.",
errorResponse.equals(errorResponse));
}

@Test
public void testEquals_NullObject() throws IOException {
Response response = new Response(200, "OK", Collections.<String, String>emptyMap(), "Body content here");
FacebookAccessTokenErrorResponse errorResponse = new FacebookAccessTokenErrorResponse(
"Message", "Type", 100, "TraceID", response);

assertFalse("Should return false when comparing to null.",
errorResponse.equals(null));
}

@Test
public void testEquals_DifferentClass() throws IOException {
Response response = new Response(200, "OK", Collections.<String, String>emptyMap(), "Body content here");
FacebookAccessTokenErrorResponse errorResponse = new FacebookAccessTokenErrorResponse(
"Message", "Type", 100, "TraceID", response);
Object otherObject = new Object();

assertFalse("Should return false when comparing different classes.",
errorResponse.equals(otherObject));
}

@Test
public void testEquals_DifferentErrorMessage() throws IOException {
Response response = new Response(200, "OK", Collections.<String, String>emptyMap(), "Body content here");
FacebookAccessTokenErrorResponse errorResponse1 = new FacebookAccessTokenErrorResponse(
"Message1", "Type", 100, "TraceID", response);
FacebookAccessTokenErrorResponse errorResponse2 = new FacebookAccessTokenErrorResponse(
"Message2", "Type", 100, "TraceID", response);

assertFalse("Should return false when errorMessages are different.",
errorResponse1.equals(errorResponse2));
}

@Test
public void testEquals_DifferentType() throws IOException {
Response response = new Response(200, "OK", Collections.<String, String>emptyMap(), "Body content here");
FacebookAccessTokenErrorResponse errorResponse1 = new FacebookAccessTokenErrorResponse(
"Message", "Type1", 100, "TraceID", response);
FacebookAccessTokenErrorResponse errorResponse2 = new FacebookAccessTokenErrorResponse(
"Message", "Type2", 100, "TraceID", response);

assertFalse("Should return false when types are different.",
errorResponse1.equals(errorResponse2));
}

@Test
public void testEquals_DifferentCode() throws IOException {
Response response = new Response(200, "OK", Collections.<String, String>emptyMap(), "Body content here");
FacebookAccessTokenErrorResponse errorResponse1 = new FacebookAccessTokenErrorResponse(
"Message", "Type", 100, "TraceID", response);
FacebookAccessTokenErrorResponse errorResponse2 = new FacebookAccessTokenErrorResponse(
"Message", "Type", 101, "TraceID", response);

assertFalse("Should return false when codes are different.",
errorResponse1.equals(errorResponse2));
}

@Test
public void testEquals_DifferentFbtraceId() throws IOException {
Response response = new Response(200, "OK", Collections.<String, String>emptyMap(), "Body content here");
FacebookAccessTokenErrorResponse errorResponse1 = new FacebookAccessTokenErrorResponse(
"Message", "Type", 100, "TraceID1", response);
FacebookAccessTokenErrorResponse errorResponse2 = new FacebookAccessTokenErrorResponse(
"Message", "Type", 100, "TraceID2", response);

assertFalse("Should return false when fbtraceIds are different.",
errorResponse1.equals(errorResponse2));
}
}
13 changes: 11 additions & 2 deletions scribejava-httpclient-ning/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>com.github.scribejava</groupId>
<artifactId>scribejava</artifactId>
<version>8.3.4-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
<relativePath>../pom.xml</relativePath> <!-- ensure this actually points to the parent POM -->
</parent>

<groupId>com.github.scribejava</groupId>
Expand Down Expand Up @@ -52,11 +52,20 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration combine.self="override">
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- PMD Plugin Configuration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.19.0</version> <!-- Ensure the version is correct -->
<version>3.19.0</version>
<configuration>
<skip>true</skip>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
public class NingHttpClient extends AbstractAsyncOnlyHttpClient {

private final AsyncHttpClient client;
private static final ConcurrentHashMap<String, AtomicBoolean> branchCoverage = new ConcurrentHashMap<>();
// data structure for info about the branches
public static final ConcurrentHashMap<String, AtomicBoolean> branchCoverage = new ConcurrentHashMap<>();
// Branch coverage data structure Nikola
static {
branchCoverage.put("branch_1", new AtomicBoolean(false)); // GET
branchCoverage.put("branch_2", new AtomicBoolean(false)); // POST
branchCoverage.put("branch_3", new AtomicBoolean(false)); // PUT
branchCoverage.put("branch_4", new AtomicBoolean(false)); // DELETE
branchCoverage.put("branch_5", new AtomicBoolean(false)); // DEFAULT
branchCoverage.put("NingHttpClientdoExecuteAsync.branch_1", new AtomicBoolean(false));
branchCoverage.put("NingHttpClientdoExecuteAsync.branch_2", new AtomicBoolean(false));
branchCoverage.put("NingHttpClientdoExecuteAsync.branch_3", new AtomicBoolean(false));
branchCoverage.put("NingHttpClientdoExecuteAsync.branch_4", new AtomicBoolean(false));
branchCoverage.put("NingHttpClientdoExecuteAsync.branch_5", new AtomicBoolean(false));

Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
Expand Down Expand Up @@ -102,41 +102,39 @@ public <T> Future<T> executeAsync(String userAgent, Map<String, String> headers,
}

// branch coverage: Nikola
private <T> Future<T> doExecuteAsync(String userAgent, Map<String, String> headers, Verb httpVerb,
public <T> Future<T> doExecuteAsync(String userAgent, Map<String, String> headers, Verb httpVerb,
String completeUrl, BodySetter bodySetter, Object bodyContents, OAuthAsyncRequestCallback<T> callback,
OAuthRequest.ResponseConverter<T> converter) {
final AsyncHttpClient.BoundRequestBuilder boundRequestBuilder;
switch (httpVerb) {
// ID: branch_1
case GET:
branchCoverage.get("branch_1").set(true); // Update branch coverage for GET
branchCoverage.get("NingHttpClientdoExecuteAsync.branch_1").set(true);
boundRequestBuilder = client.prepareGet(completeUrl);
break;
// ID: branch_2
case POST:
branchCoverage.get("branch_2").set(true); // Update branch coverage for POST
branchCoverage.get("NingHttpClientdoExecuteAsync.branch_2").set(true);
boundRequestBuilder = client.preparePost(completeUrl);
break;
// ID: branch_3
case PUT:
branchCoverage.get("branch_3").set(true); // Update branch coverage for PUT
branchCoverage.get("NingHttpClientdoExecuteAsync.branch_3").set(true);
boundRequestBuilder = client.preparePut(completeUrl);
break;
// ID: branch_4
case DELETE:
branchCoverage.get("branch_4").set(true); // Update branch coverage for DELETE
branchCoverage.get("NingHttpClientdoExecuteAsync.branch_4").set(true);
boundRequestBuilder = client.prepareDelete(completeUrl);
break;
// ID: branch_5
default:
branchCoverage.get("branch_5").set(true); // Update branch coverage for DEFAULT case
branchCoverage.get("NingHttpClientdoExecuteAsync.branch_5").set(true);
throw new IllegalArgumentException("message build error: unknown verb type");
}

if (httpVerb.isPermitBody()) {
// Check if the Content-Type header is already present
if (!headers.containsKey("Content-Type")) {
// Set the Content-Type header if not present
boundRequestBuilder.addHeader("Content-Type", "application/x-www-form-urlencoded");
}
bodySetter.setBody(boundRequestBuilder, bodyContents);
Expand All @@ -154,7 +152,7 @@ private <T> Future<T> doExecuteAsync(String userAgent, Map<String, String> heade
}


private enum BodySetter {
public enum BodySetter {
BYTE_ARRAY {
@Override
AsyncHttpClient.BoundRequestBuilder setBody(AsyncHttpClient.BoundRequestBuilder requestBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,76 @@

import com.github.scribejava.core.AbstractClientTest;
import com.github.scribejava.core.httpclient.HttpClient;
import com.github.scribejava.core.model.Verb;
import org.junit.Test;
import java.util.Map;
import java.util.HashMap;
import java.util.concurrent.Future;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.concurrent.Future;

import static org.junit.Assert.fail;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;




public class NingHttpClientTest extends AbstractClientTest {

@Override
protected HttpClient createNewClient() {
return new NingHttpClient();
}




@Test
public void testDoExecuteAsyncPut() {
NingHttpClient client = (NingHttpClient) createNewClient();
String completeUrl = "http://example.com/put";
Map<String, String> headers = new HashMap<>();

Future<?> future = client.doExecuteAsync("TestAgent", headers, Verb.PUT, completeUrl, NingHttpClient.BodySetter.STRING, "", null, null);

assertTrue(NingHttpClient.branchCoverage.get("NingHttpClientdoExecuteAsync.branch_3").get());
assertNotNull(future);
}



@Test
public void testDoExecuteAsyncDelete() {
NingHttpClient client = (NingHttpClient) createNewClient();
String completeUrl = "http://example.com/delete";
Map<String, String> headers = new HashMap<>();
Future<?> future = client.doExecuteAsync("TestAgent", headers, Verb.DELETE, completeUrl, NingHttpClient.BodySetter.STRING, "", null, null);

assertTrue(NingHttpClient.branchCoverage.get("NingHttpClientdoExecuteAsync.branch_4").get());
assertNotNull(future);
}


@Test(expected = IllegalArgumentException.class)
public void testDoExecuteAsyncDefault() {
NingHttpClient client = (NingHttpClient) createNewClient();
String completeUrl = "http://example.com/default";
Map<String, String> headers = new HashMap<>();

// Attempt to use the UNSUPPORTED verb, expecting an IllegalArgumentException
client.doExecuteAsync("TestAgent", headers, Verb.TRACE, completeUrl, NingHttpClient.BodySetter.STRING, "", null, null);

fail("Expected an IllegalArgumentException to be thrown for UNSUPPORTED verb.");
}






}