org.sonatype.goodies.httpfixture.server.fluent.Behaviours Java Examples

The following examples show how to use org.sonatype.goodies.httpfixture.server.fluent.Behaviours. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ComposerProxyIT.java    From nexus-repository-composer with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
  server = Server.withPort(0)
      .serve("/" + FILE_PACKAGES)
      .withBehaviours(Behaviours.file(testData.resolveFile(FILE_PACKAGES)))
      .serve("/" + VALID_LIST_URL)
      .withBehaviours(Behaviours.file(testData.resolveFile(FILE_LIST)))
      .serve("/" + VALID_PROVIDER_URL)
      .withBehaviours(Behaviours.file(testData.resolveFile(FILE_PROVIDER)))
      .serve("/" + VALID_ZIPBALL_URL)
      .withBehaviours(Behaviours.file(testData.resolveFile(ZIPBALL_FILE_NAME)))
      .start();

  proxyRepo = repos.createComposerProxy("composer-test-proxy", server.getUrl().toExternalForm());
  proxyClient = composerClient(proxyRepo);
}
 
Example #2
Source File: CleanupTaskConanProxyIT.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
  BaseUrlHolder.set(this.nexusUrl.toString());
  testData.addDirectory(NexusPaxExamSupport.resolveBaseFile("target/it-resources/conan"));
  testData.addDirectory(NexusPaxExamSupport.resolveBaseFile("target/test-classes/conan"));

  server = Server.withPort(0)
      .serve("/" + JSON_FOR_MODERN_CPP_URL)
      .withBehaviours(Behaviours.file(testData.resolveFile(DOWNLOAD_URLS_FILE_NAME)))
      .serve("/" + LIB_URL)
      .withBehaviours(Behaviours.file(testData.resolveFile(LIB_DOWNLOAD_URLS_FILE_NAME)))
      .start();

  proxyRepo = repos.createConanProxy(testName.getMethodName(), server.getUrl().toExternalForm());
  URL repositoryUrl = repositoryBaseUrl(proxyRepo);
  proxyClient = new ConanClient(
      clientBuilder(repositoryUrl).build(),
      clientContext(),
      repositoryUrl.toURI()
  );
  proxyClient.get(JSON_FOR_MODERN_CPP_URL);
}
 
Example #3
Source File: CleanupTaskP2ProxyIT.java    From nexus-repository-p2 with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  BaseUrlHolder.set(this.nexusUrl.toString());
  testData.addDirectory(NexusPaxExamSupport.resolveBaseFile("target/test-classes/p2"));
  server = Server.withPort(0)
      .serve("/" + VALID_PACKAGE_URL)
      .withBehaviours(Behaviours.file(testData.resolveFile(PACKAGE_NAME)))
      .serve("/" + VALID_HELP_PACKAGE_URL)
      .withBehaviours(Behaviours.file(testData.resolveFile(HELP_PACKAGE_NAME)))
      .start();

  proxyRepo = repos.createP2Proxy(testName.getMethodName(), server.getUrl().toExternalForm());
  proxyClient = p2Client(proxyRepo);
  deployArtifacts(VALID_HELP_PACKAGE_URL);
}
 
Example #4
Source File: P2RestoreBlobIT.java    From nexus-repository-p2 with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  BaseUrlHolder.set(this.nexusUrl.toString());

  proxyServer = Server.withPort(0)
      .serve("/" + VALID_PACKAGE_URL)
      .withBehaviours(Behaviours.file(testData.resolveFile(PACKAGE_NAME)))
      .start();

  proxyRepository = repos.createP2Proxy(P2ProxyRecipe.NAME, "http://localhost:" + proxyServer.getPort() + "/");
  proxyClient = p2Client(proxyRepository);

  assertThat(proxyClient.get(VALID_PACKAGE_URL).getStatusLine().getStatusCode(), is(HttpStatus.OK));
}
 
Example #5
Source File: ConanProxySearchIT.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  BaseUrlHolder.set(this.nexusUrl.toString());

  server = Server
      .withPort(CONAN_REMOTE_PORT)

      // we should make sure that proxy will not use download_urls
      .serve("/" + PATH_DOWNLOAD_URLS)
      .withBehaviours(Behaviours.error(501))

      .serve("/" + PATH_PATTERN_SEARCH)
      .withBehaviours(Behaviours.content(MOCK_PATTERN_SEARCH_REMOTE_RESPONSE, ContentTypes.APPLICATION_JSON))

      .serve("/" + PATH_SEARCH)
      .withBehaviours(Behaviours.content(MOCK_SEARCH_REMOTE_RESPONSE, ContentTypes.APPLICATION_JSON))

      .serve("/" + PATH_DIGEST)
      .withBehaviours(Behaviours.file(testData.resolveFile(FILE_DIGEST)))

      .serve("/" + PATH_MANIFEST)
      .withBehaviours(Behaviours.file(testData.resolveFile(FILE_MANIFEST)))

      .start();

  proxyRepo = repos.createConanProxy(NXRM_CONAN_PROXY_REPO_NAME, server.getUrl().toExternalForm());
  proxyClient = conanClient(proxyRepo);
}
 
Example #6
Source File: ConanRoutingRuleIT.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  server = Server.withPort(0).serve("/" + JSON_FOR_MODERN_CPP_URL)
      .withBehaviours(Behaviours.file(testData.resolveFile(DOWNLOAD_URLS_FILE_NAME)))
      .serve("/" + JSON_FOR_MODERN_CPP_BLOCKED_URL)
      .withBehaviours(Behaviours.file(testData.resolveFile(DOWNLOAD_URLS_FILE_NAME)))
      .start();

  proxyRepo = repos.createConanProxy(testName.getMethodName(), server.getUrl().toExternalForm());
  proxyClient = conanClient(proxyRepo);
  EntityId routingRuleId = createBlockedRoutingRule("conan-rule", BLOCKED_VENDOR_REGEX);
  attachRuleToRepository(proxyRepo, routingRuleId);
}
 
Example #7
Source File: ConanProxyIT.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  BaseUrlHolder.set(this.nexusUrl.toString());

  server = Server.withPort(CONAN_REMOTE_PORT)
      .serve("/" + PATH_DOWNLOAD_URLS)
      .withBehaviours(Behaviours.file(testData.resolveFile(FILE_DOWNLOAD_URLS)))
      .serve("/" + PATH_DIGEST)
      .withBehaviours(Behaviours.file(testData.resolveFile(FILE_DIGEST)))
      .serve("/" + PATH_DOWNLOAD_URLS_WITHOUT_PACKAGES)
      .withBehaviours(Behaviours.file(testData.resolveFile(FILE_DOWNLOAD_URLS_NON_PACKAGE)))
      .serve("/" + LIB_WITH_WRONG_CONANINFO_HASH_DOWNLOAD_URLS_PATH)
      .withBehaviours(Behaviours.file(testData.resolveFile(LIB_WITH_WRONG_CONANINFO_HASH_DOWNLOAD_URLS_FILE_NAME)))
      .serve("/" + PATH_TGZ_PACKAGE)
      .withBehaviours(Behaviours.file(testData.resolveFile(FILE_PACKAGE)))
      .serve("/" + PATH_INFO)
      .withBehaviours(Behaviours.file(testData.resolveFile(FILE_INFO)))
      .serve("/" + LIB_WITH_WRONG_CONANINFO_HASH_CONANINFO_PATH)
      .withBehaviours(Behaviours.file(testData.resolveFile(FILE_INFO)))
      .serve("/" + PATH_MANIFEST)
      .withBehaviours(Behaviours.file(testData.resolveFile(FILE_MANIFEST)))
      .serve("/" + LIB_WITH_WRONG_CONANINFO_HASH_CONANMANIFEST_PATH)
      .withBehaviours(Behaviours.file(testData.resolveFile(LIB_WITH_WRONG_CONANINFO_HASH_CONANMANIFEST_FILE_NAME)))
      .start();

  proxyRepo = repos.createConanProxy(NXRM_CONAN_PROXY_REPO_NAME, server.getUrl().toExternalForm());
  proxyClient = conanClient(proxyRepo);
  proxyClient.getHttpResponse(PATH_DOWNLOAD_URLS);
}
 
Example #8
Source File: RawProxyOfHostedIT.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void responseViaProxyProduces(final int upstreamStatus, final int downstreamStatus) throws Exception {
  Server server = Server.withPort(0).serve("/*").withBehaviours(Behaviours.error(upstreamStatus)).start();
  try {
    proxyClient = rawClient(repos.createRawProxy("raw-test-proxy-" + upstreamStatus + "-" + downstreamStatus,
        server.getUrl().toExternalForm()));
    assertThat(status(proxyClient.get(TEST_PATH)), is(downstreamStatus));
  }
  finally {
    server.stop();
  }
}
 
Example #9
Source File: RawProxyOfHostedIT.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void responseViaGroupProduces(final int upstreamStatus, final int downstreamStatus) throws Exception {
  Server server = Server.withPort(0).serve("/*").withBehaviours(Behaviours.error(upstreamStatus)).start();
  try {
    Repository proxy = repos.createRawProxy("raw-test-proxy-" + upstreamStatus + "-" + downstreamStatus,
        server.getUrl().toExternalForm());
    Repository group = repos.createRawGroup("raw-test-group-" + upstreamStatus + "-" + downstreamStatus,
        proxy.getName());
    proxyClient = rawClient(group);
    assertThat(status(proxyClient.get(TEST_PATH)), is(downstreamStatus));
  }
  finally {
    server.stop();
  }
}
 
Example #10
Source File: RawProxyIT.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void responseViaGroupProduces(final int upstreamStatus, final int downstreamStatus) throws Exception {
  Server server = Server.withPort(0).serve("/*").withBehaviours(Behaviours.error(upstreamStatus)).start();
  try {
    Repository proxy = repos.createRawProxy("raw-test-proxy-" + upstreamStatus + "-" + downstreamStatus,
        server.getUrl().toExternalForm());
    Repository group = repos.createRawGroup("raw-test-group-" + upstreamStatus + "-" + downstreamStatus,
        proxy.getName());
    proxyClient = rawClient(group);
    assertThat(status(proxyClient.get(TEST_PATH)), is(downstreamStatus));
  }
  finally {
    server.stop();
  }
}
 
Example #11
Source File: RawProxyIT.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void responseViaProxyProduces(final int upstreamStatus, final int downstreamStatus) throws Exception {
  Server server = Server.withPort(0).serve("/*").withBehaviours(Behaviours.error(upstreamStatus)).start();
  try {
    proxyClient = rawClient(repos.createRawProxy("raw-test-proxy-" + upstreamStatus + "-" + downstreamStatus,
        server.getUrl().toExternalForm()));
    assertThat(status(proxyClient.get(TEST_PATH)), is(downstreamStatus));
  }
  finally {
    server.stop();
  }
}
 
Example #12
Source File: P2ProxyIT.java    From nexus-repository-p2 with Eclipse Public License 1.0 4 votes vote down vote up
@Before
public void setup() throws Exception {
  server = Server.withPort(0)
      .serve("/" + VALID_PACKAGE_URL)
      .withBehaviours(Behaviours.file(testData.resolveFile(PACKAGE_NAME)))
      .serve("/" + ARTIFACT_JAR)
      .withBehaviours(Behaviours.file(testData.resolveFile(ARTIFACT_JAR)))
      .serve("/" + ARTIFACT_XML_TEST_PATH)
      .withBehaviours(Behaviours.file(testData.resolveFile(ARTIFACT_XML)))
      .serve("/" + ARTIFACT_XML_XZ_TEST_PATH)
      .withBehaviours(Behaviours.file(testData.resolveFile(ARTIFACT_XML_XZ)))
      .serve("/" + P2_INDEX)
      .withBehaviours(Behaviours.file(testData.resolveFile(P2_INDEX)))
      .serve("/folder/" + P2_INDEX)
      .withBehaviours(Behaviours.file(testData.resolveFile(P2_INDEX)))
      .serve("/" + COMPOSITE_ARTIFACTS_JAR)
      .withBehaviours(Behaviours.file(testData.resolveFile(COMPOSITE_ARTIFACTS_JAR)))
      .serve("/" + COMPOSITE_ARTIFACTS_XML)
      .withBehaviours(Behaviours.file(testData.resolveFile(COMPOSITE_ARTIFACTS_XML)))
      .serve("/" + COMPOSITE_CONTENT_JAR)
      .withBehaviours(Behaviours.file(testData.resolveFile(COMPOSITE_CONTENT_JAR)))
      .serve("/" + COMPOSITE_CONTENT_XML)
      .withBehaviours(Behaviours.file(testData.resolveFile(COMPOSITE_CONTENT_XML)))
      .serve("/" + CONTENT_XML_PATH)
      .withBehaviours(Behaviours.file(testData.resolveFile(CONTENT_XML)))
      .serve("/" + CONTENT_JAR_PATH)
      .withBehaviours(Behaviours.file(testData.resolveFile(CONTENT_JAR)))
      .serve("/" + CONTENT_XML_XZ_PATH)
      .withBehaviours(Behaviours.file(testData.resolveFile(CONTENT_XML_XZ)))
      .serve("/" + BINARY_TEST_PATH)
      .withBehaviours(Behaviours.file(testData.resolveFile(BINARY)))
      .serve("/" + PLUGIN_TEST_PATH)
      .withBehaviours(Behaviours.file(testData.resolveFile(PLUGIN)))
      .serve("/" + FEATURE_TEST_PATH)
      .withBehaviours(Behaviours.file(testData.resolveFile(FEATURE)))
      .serve("/" + ACCELEO_COMPONENT_NAME + ACCELEO_COMPONENT_VERSION + "/features/" + ACCELEO_FEATURE_JAR)
      .withBehaviours(Behaviours.file(testData.resolveFile(ACCELEO_FEATURE_JAR)))
      .serve("/" + ACCELEO_COMPONENT_NAME + ACCELEO_COMPONENT_VERSION + "/plugins/" + ACCELEO_PLUGIN_GZ)
      .withBehaviours(Behaviours.file(testData.resolveFile(ACCELEO_PLUGIN_GZ)))
      .start();

  proxyRepo = repos.createP2Proxy("p2-test-proxy", server.getUrl().toExternalForm());
  proxyClient = p2Client(proxyRepo);
}
 
Example #13
Source File: P2RoutingRuleIT.java    From nexus-repository-p2 with Eclipse Public License 1.0 4 votes vote down vote up
private void configureProxyBehaviour(final String proxyPath, final String fileName) {
  File file = resolveTestFile(fileName);
  BehaviourSpy spy = new BehaviourSpy(Behaviours.file(file));
  proxyServer.serve("/" + proxyPath).withBehaviours(spy);
  serverPaths.put(proxyPath, spy);
}
 
Example #14
Source File: HelmRoutingRuleIT.java    From nexus-repository-helm with Eclipse Public License 1.0 4 votes vote down vote up
private void configureProxyBehaviour(final String proxyPath, final String fileName) {
  File file = resolveTestFile(fileName);
  BehaviourSpy spy = new BehaviourSpy(Behaviours.file(file));
  proxyServer.serve("/" + proxyPath).withBehaviours(spy);
  serverPaths.put(proxyPath, spy);
}
 
Example #15
Source File: RRoutingRuleIT.java    From nexus-repository-r with Eclipse Public License 1.0 4 votes vote down vote up
private void configureProxyBehaviour(final String proxyPath, final String fileName) {
  File file = resolveTestFile(fileName);
  BehaviourSpy spy = new BehaviourSpy(Behaviours.file(file));
  proxyServer.serve("/" + proxyPath).withBehaviours(spy);
  serverPaths.put(proxyPath, spy);
}
 
Example #16
Source File: RawRestoreBlobIT.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private Content resolveFile(final String filename) {
  return Behaviours.file(testData.resolveFile(filename));
}