-
-
Save secondsun/8478a5f0527fc97b2456 to your computer and use it in GitHub Desktop.
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
@RunWith(RobolectricTestRunner.class) | |
public class ModularizedPipelineTest { | |
private URL url; | |
@Before | |
public void setup() throws MalformedURLException { | |
url = new URL("http://server.com/context/"); | |
} | |
@Test | |
public void defaultPipeSetup() { | |
Pipe newPipe = Pipeline2.config(PipeConfiguration.class, "data").withUrl(url).forClass(Data.class); | |
assertEquals("verifying the given URL", "http://server.com/context/data", newPipe.getUrl().toString()); | |
assertEquals("verifying the type", REST, newPipe.getType()); | |
} | |
/** | |
* This test will show that the Pipe URL Creation can be overriden | |
*/ | |
@Test | |
public void customPipeSetup() { | |
Pipe newPipe = Pipeline2.config(IStubPipeConfiguration.class, "custom").withUrl(url).id(5).forClass(Data.class); | |
assertEquals("verifying the given URL", "http://server.com/context/data/5", newPipe.getUrl().toString()); | |
} | |
/** | |
* This test will show that auth can be added to a pipe. | |
* | |
* @throws java.lang.NoSuchFieldException thrown by Java, shouldn't happen if the test works. | |
* @throws java.lang.IllegalArgumentException thrown by Java, shouldn't happen if the test works. | |
* @throws java.lang.IllegalAccessException thrown by Java, shouldn't happen if the test works. | |
*/ | |
@Test | |
public void addAuthToPipe() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException { | |
AuthenticationModule basicModule = new HttpBasicAuthenticationModule(url); | |
Pipe newPipe = Pipeline2.config(PipeConfiguration.class, "auth").withUrl(url).module(basicModule).forClass(Data.class); | |
RestRunner runner = getPrivateField(newPipe, "restRunner", RestRunner.class); | |
AuthenticationModule module = getPrivateField(runner, "authModule", AuthenticationModule.class); | |
//For now we will assume that if the module is set correctly then | |
//restRunner will call it correctly. | |
assertEquals(basicModule, module); | |
/* | |
TODO: Eventually we will want to break the dependency on the | |
AuthenticationModule type from RestRunner. This will happen | |
during modularization and this test will be rewritten | |
*/ | |
} | |
/** | |
* This test will show that authz can be added to a pipe. | |
* | |
* @throws java.lang.NoSuchFieldException thrown by Java, shouldn't happen if the test works. | |
* @throws java.lang.IllegalArgumentException thrown by Java, shouldn't happen if the test works. | |
* @throws java.lang.IllegalAccessException thrown by Java, shouldn't happen if the test works. | |
*/ | |
@Test | |
public void addAuthzToPipe() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException { | |
AuthzModule authzModule = mock(AuthzModule.class); | |
Pipe newPipe = Pipeline2.config(PipeConfiguration.class, "auth").withUrl(url).module(authzModule).forClass(Data.class); | |
RestRunner runner = getPrivateField(newPipe, "restRunner", RestRunner.class); | |
AuthzModule module = getPrivateField(runner, "authzModule", AuthzModule.class); | |
//For now we will assume that if the module is set correctly then | |
//restRunner will call it correctly. | |
assertEquals(authzModule, module); | |
/* | |
TODO: Eventually we will want to break the dependency on the | |
AuthzModule type from RestRunner. This will happen | |
during modularization and this test will be rewritten | |
*/ } | |
/** | |
* This test will show paging handling can be added to a Pipeline | |
* | |
*/ | |
@Test | |
public void addPagingToPipe() { | |
PageConfig pageConfig = new PageConfig(); | |
Pipe newPipe = Pipeline2.config(PipeConfiguration.class, "auth").withUrl(url).pageConfig(pageConfig).forClass(Data.class); | |
throw new IllegalStateException("Not yet implemented"); | |
/* | |
TODO: Refactor paging perhaps to be more modular? | |
Refactor PageConfig to extend PipeConfiguration and make the builder more fluent? | |
*/ | |
} | |
/** | |
* This test will show that the upload mechanism can be swapped to | |
* multipart. | |
* | |
* @throws java.lang.NoSuchFieldException thrown by Java, shouldn't happen if the test works. | |
* @throws java.lang.IllegalArgumentException thrown by Java, shouldn't happen if the test works. | |
* @throws java.lang.IllegalAccessException thrown by Java, shouldn't happen if the test works. | |
*/ | |
@Test | |
public void addMultipartToPipe() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException { | |
RequestBuilder multipartBuilder = new MultipartRequestBuilder(); | |
Pipe newPipe = Pipeline2.config(PipeConfiguration.class, "auth").withUrl(url).requestBuilder(multipartBuilder).forClass(Data.class); | |
RestRunner runner = getPrivateField(newPipe, "restRunner", RestRunner.class); | |
RequestBuilder runnerBuilder = runner.getRequestBuilder(); | |
assertEquals(multipartBuilder, runnerBuilder); | |
/* | |
TODO: What should happen when requestBuilders are chained? | |
*/ | |
} | |
private static interface IStubPipeConfiguration extends PipeConfiguration<IStubPipeConfiguration> { | |
IStubPipeConfiguration id(int id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment