-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
286 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...ntroller/src/main/java/com/github/restup/controller/settings/BasicControllerSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.github.restup.controller.settings; | ||
|
||
import com.github.restup.controller.ExceptionHandler; | ||
import com.github.restup.controller.content.negotiation.ContentNegotiator; | ||
import com.github.restup.controller.interceptor.RequestInterceptor; | ||
import com.github.restup.controller.request.parser.RequestParser; | ||
import com.github.restup.registry.ResourceRegistry; | ||
|
||
public class BasicControllerSettings implements ControllerSettings { | ||
|
||
private final ResourceRegistry registry; | ||
private final ContentNegotiator[] contentNegotiators; | ||
private final RequestInterceptor requestInterceptor; | ||
private final RequestParser requestParser; | ||
private final ExceptionHandler exceptionHandler; | ||
private final String defaultMediaType; | ||
|
||
protected BasicControllerSettings(ResourceRegistry registry, ContentNegotiator[] contentNegotiators, | ||
RequestInterceptor requestInterceptor, RequestParser requestParsers, | ||
ExceptionHandler exceptionHandler, String defaultMediaType) { | ||
super(); | ||
this.registry = registry; | ||
this.contentNegotiators = contentNegotiators; | ||
this.requestInterceptor = requestInterceptor; | ||
this.requestParser = requestParsers; | ||
this.exceptionHandler = exceptionHandler; | ||
this.defaultMediaType = defaultMediaType; | ||
} | ||
|
||
@Override | ||
public String getDefaultMediaType() { | ||
return defaultMediaType; | ||
} | ||
|
||
@Override | ||
public ResourceRegistry getRegistry() { | ||
return registry; | ||
} | ||
|
||
@Override | ||
public ContentNegotiator[] getContentNegotiators() { | ||
return contentNegotiators; | ||
} | ||
|
||
@Override | ||
public RequestInterceptor getRequestInterceptor() { | ||
return requestInterceptor; | ||
} | ||
|
||
@Override | ||
public RequestParser getRequestParser() { | ||
return requestParser; | ||
} | ||
|
||
@Override | ||
public ExceptionHandler getExceptionHandler() { | ||
return exceptionHandler; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...t/java/com/github/restup/controller/content/negotiation/DefaultContentNegotiatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.github.restup.controller.content.negotiation; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyZeroInteractions; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import com.github.restup.controller.model.ParsedResourceControllerRequest; | ||
import com.github.restup.controller.model.ResourceControllerRequest; | ||
import com.github.restup.controller.model.ResourceControllerResponse; | ||
import com.github.restup.controller.model.result.JsonApiResult; | ||
import com.github.restup.test.assertions.Assertions; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class DefaultContentNegotiatorTest { | ||
|
||
@Mock | ||
ContentNegotiator contentNegotiator; | ||
|
||
@Test | ||
public void testAccept() { | ||
DefaultContentNegotiator defaultContentNegotiator = new DefaultContentNegotiator(contentNegotiator); | ||
ResourceControllerRequest request = mock(ResourceControllerRequest.class); | ||
assertTrue(defaultContentNegotiator.accept(request)); | ||
verifyZeroInteractions(contentNegotiator, request); | ||
} | ||
|
||
@Test | ||
public void testFormatResponse() { | ||
DefaultContentNegotiator defaultContentNegotiator = new DefaultContentNegotiator(contentNegotiator); | ||
ParsedResourceControllerRequest<?> request = mock(ParsedResourceControllerRequest.class); | ||
ResourceControllerResponse response = mock(ResourceControllerResponse.class); | ||
JsonApiResult result = mock(JsonApiResult.class); | ||
defaultContentNegotiator.formatResponse(request, response, result); | ||
verify(contentNegotiator).formatResponse(request, response, result); | ||
verifyZeroInteractions(contentNegotiator, request); | ||
} | ||
|
||
@Test | ||
public void testGetContentNegotiator() { | ||
Assertions.assertThrows(() -> DefaultContentNegotiator.getContentNegotiator("text/foo", contentNegotiator), IllegalArgumentException.class); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...t/java/com/github/restup/controller/content/negotiation/HalJsonContentNegotiatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.github.restup.controller.content.negotiation; | ||
|
||
import static org.junit.Assert.assertSame; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
import java.util.Collections; | ||
import org.junit.Test; | ||
import com.github.restup.controller.model.MediaType; | ||
import com.github.restup.controller.model.ParsedResourceControllerRequest; | ||
import com.github.restup.controller.model.ResourceControllerResponse; | ||
import com.github.restup.controller.model.result.HalJsonResult; | ||
import com.github.restup.registry.Resource; | ||
|
||
public class HalJsonContentNegotiatorTest { | ||
|
||
|
||
@Test | ||
public void testFormatResponse() { | ||
String foo = "foo"; | ||
ResourceControllerResponse response = mock(ResourceControllerResponse.class); | ||
|
||
ParsedResourceControllerRequest<?> request = mock(ParsedResourceControllerRequest.class); | ||
when(request.getRequestedQueries()).thenReturn(Collections.emptyList()); | ||
when(request.getResource()).thenReturn(mock(Resource.class)); | ||
HalJsonResult result = (HalJsonResult) new HalJsonContentNegotiator().formatResponse(request, response, foo); | ||
assertSame(foo, result.getResult()); | ||
verify(response).setHeader(ContentTypeNegotiation.CONTENT_TYPE, MediaType.APPLICATION_JSON_HAL.getContentType()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...t/java/com/github/restup/controller/content/negotiation/JsonApiContentNegotiatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.github.restup.controller.content.negotiation; | ||
|
||
import static org.junit.Assert.assertSame; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
import java.util.Collections; | ||
import org.junit.Test; | ||
import com.github.restup.controller.linking.LinkBuilderFactory; | ||
import com.github.restup.controller.model.MediaType; | ||
import com.github.restup.controller.model.ParsedResourceControllerRequest; | ||
import com.github.restup.controller.model.ResourceControllerResponse; | ||
import com.github.restup.controller.model.result.JsonApiResult; | ||
import com.github.restup.registry.Resource; | ||
|
||
public class JsonApiContentNegotiatorTest { | ||
|
||
|
||
@Test | ||
public void testFormatResponse() { | ||
String foo = "foo"; | ||
ResourceControllerResponse response = mock(ResourceControllerResponse.class); | ||
|
||
ParsedResourceControllerRequest<?> request = mock(ParsedResourceControllerRequest.class); | ||
when(request.getRequestedQueries()).thenReturn(Collections.emptyList()); | ||
when(request.getResource()).thenReturn(mock(Resource.class)); | ||
JsonApiResult result = (JsonApiResult) new JsonApiContentNegotiator(mock(LinkBuilderFactory.class)).formatResponse(request, response, foo); | ||
assertSame(foo, result.getResult()); | ||
verify(response).setHeader(ContentTypeNegotiation.CONTENT_TYPE, MediaType.APPLICATION_JSON_API.getContentType()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
.../src/test/java/com/github/restup/controller/model/BasicResourceControllerRequestTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.github.restup.controller.model; | ||
|
||
import static org.junit.Assert.assertNull; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import org.junit.Test; | ||
|
||
public class BasicResourceControllerRequestTest { | ||
|
||
@Test | ||
public void testGetHeaders() { | ||
BasicResourceControllerRequest request = mock(BasicResourceControllerRequest.class); | ||
when(request.getHeaders("foo")).thenCallRealMethod(); | ||
assertNull(request.getHeaders("foo")); | ||
} | ||
|
||
} |
Oops, something went wrong.