Search in sources :

Example 1 with MockHttpRequest

use of org.jboss.resteasy.mock.MockHttpRequest in project kie-wb-common by kiegroup.

the class MavenRestHandlerTest method post.

@Test
public void post() {
    // Start preparation FS
    try {
        fileSystemTestingUtils.setup();
        ioService = fileSystemTestingUtils.getIoService();
        final String repoName = "myrepo";
        final JGitFileSystem fs = (JGitFileSystem) ioService.newFileSystem(URI.create("git://" + repoName), new HashMap<String, Object>() {

            {
                put("init", Boolean.TRUE);
                put("internal", Boolean.TRUE);
            }
        });
        ioService.startBatch(fs);
        String pom = "target/test-classes/kjar-2-single-resources/pom.xml";
        if (!runIntoMavenCLI) {
            pom = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/pom.xml";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File(pom).toPath())));
        String personDotJava = "target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java";
        if (!runIntoMavenCLI) {
            personDotJava = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java"), new String(java.nio.file.Files.readAllBytes(new File(personDotJava).toPath())));
        String simpleRulesDotDRL = "target/test-classes/kjar-2-single-resources/src/main/resources/AllResourcesTypes/simple-rules.drl";
        if (!runIntoMavenCLI) {
            simpleRulesDotDRL = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/resources/AllResourceTypes/simple-rules.drl";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/src/main/resources/AllResourcesTypes/simple-rules.drl"), new String(java.nio.file.Files.readAllBytes(new File(simpleRulesDotDRL).toPath())));
        String kmodule = "target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml";
        if (!runIntoMavenCLI) {
            kmodule = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml"), new String(java.nio.file.Files.readAllBytes(new File(kmodule).toPath())));
        ioService.endBatch();
        java.nio.file.Path tmpRootCloned = java.nio.file.Files.createTempDirectory("cloned");
        java.nio.file.Path tmpCloned = java.nio.file.Files.createDirectories(java.nio.file.Paths.get(tmpRootCloned.toString(), "dummy"));
        final File gitClonedFolder = new File(tmpCloned.toFile(), ".clone.git");
        final Git cloned = Git.cloneRepository().setURI(fs.getGit().getRepository().getDirectory().toURI().toString()).setBare(false).setDirectory(gitClonedFolder).call();
        assertThat(cloned).isNotNull();
        mavenRepoPath = java.nio.file.Paths.get(System.getProperty("user.home"), ".m2", "repository");
        tmpRoot = java.nio.file.Paths.get(gitClonedFolder + "/dummy/");
        // END preparation FS
        Dispatcher dispatcher = new AsynchronousDispatcher(new ResteasyProviderFactory());
        ResteasyProviderFactory.setInstance(dispatcher.getProviderFactory());
        RegisterBuiltin.register(dispatcher.getProviderFactory());
        POJOResourceFactory noDefaults = new POJOResourceFactory(MavenRestHandler.class);
        dispatcher.getRegistry().addResourceFactory(noDefaults);
        MockHttpRequest request = MockHttpRequest.create("POST", "build/maven/");
        request.header("project", tmpRoot.toAbsolutePath().toString() + "/dummy").header("mavenrepo", mavenRepoPath.toAbsolutePath().toString());
        MockHttpResponse response = new MockHttpResponse();
        SynchronousExecutionContext synchronousExecutionContext = new SynchronousExecutionContext((SynchronousDispatcher) dispatcher, request, response);
        request.setAsynchronousContext(synchronousExecutionContext);
        dispatcher.invoke(request, response);
        assertThat(response.getStatus()).isEqualTo(200);
        byte[] serializedCompilationResponse = response.getOutput();
        HttpCompilationResponse res = RestUtils.readDefaultCompilationResponseFromBytes(serializedCompilationResponse);
        assertThat(res).isNotNull();
        assertThat(res.getDependencies()).hasSize(4);
        assertThat(res.getTargetContent()).hasSize(3);
        tearDown();
    } catch (Exception e) {
        logger.error(e.getMessage());
    } finally {
        fileSystemTestingUtils.cleanup();
    }
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) HttpCompilationResponse(org.kie.workbench.common.services.backend.compiler.HttpCompilationResponse) HashMap(java.util.HashMap) SynchronousDispatcher(org.jboss.resteasy.core.SynchronousDispatcher) AsynchronousDispatcher(org.jboss.resteasy.core.AsynchronousDispatcher) Dispatcher(org.jboss.resteasy.core.Dispatcher) SynchronousExecutionContext(org.jboss.resteasy.core.SynchronousExecutionContext) POJOResourceFactory(org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory) Git(org.eclipse.jgit.api.Git) AsynchronousDispatcher(org.jboss.resteasy.core.AsynchronousDispatcher) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) File(java.io.File) Path(java.nio.file.Path) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) Test(org.junit.Test)

Example 2 with MockHttpRequest

use of org.jboss.resteasy.mock.MockHttpRequest in project candlepin by candlepin.

the class AuthUtilTest method testGetHeaderDoesNotExist.

@Test
public void testGetHeaderDoesNotExist() throws Exception {
    MockHttpRequest req = MockHttpRequest.create("GET", "http://localhost/candlepin/status");
    req.header("test_header", "value");
    String result = AuthUtil.getHeader(req, "not_found");
    assertEquals("", result);
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Test(org.junit.Test)

Example 3 with MockHttpRequest

use of org.jboss.resteasy.mock.MockHttpRequest in project candlepin by candlepin.

the class AuthUtilTest method testGetHeaderExists.

@Test
public void testGetHeaderExists() throws Exception {
    MockHttpRequest req = MockHttpRequest.create("GET", "http://localhost/candlepin/status");
    req.header("test_header", "value");
    String result = AuthUtil.getHeader(req, "test_header");
    assertEquals("value", result);
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Test(org.junit.jupiter.api.Test)

Example 4 with MockHttpRequest

use of org.jboss.resteasy.mock.MockHttpRequest in project candlepin by candlepin.

the class AuthUtilTest method testGetHeaderDoesNotExist.

@Test
public void testGetHeaderDoesNotExist() throws Exception {
    MockHttpRequest req = MockHttpRequest.create("GET", "http://localhost/candlepin/status");
    req.header("test_header", "value");
    String result = AuthUtil.getHeader(req, "not_found");
    assertEquals("", result);
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Test(org.junit.jupiter.api.Test)

Example 5 with MockHttpRequest

use of org.jboss.resteasy.mock.MockHttpRequest in project candlepin by candlepin.

the class CloudRegistrationAuthTest method testGetPrincipalIgnoresTokensLackingSubject.

@Test
public void testGetPrincipalIgnoresTokensLackingSubject() {
    int ctSeconds = this.getCurrentSeconds() - 5;
    String token = this.buildMalformedToken(new JsonWebToken().type(TOKEN_TYPE).audience("test_org").issuedAt(ctSeconds).notBefore(ctSeconds).expiration(ctSeconds + 300));
    MockHttpRequest request = this.buildHttpRequest();
    request.header("Authorization", "Bearer " + token);
    Principal principal = this.buildAuthProvider().getPrincipal(request);
    assertNull(principal);
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) JsonWebToken(org.keycloak.representations.JsonWebToken) Test(org.junit.jupiter.api.Test)

Aggregations

MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)108 Test (org.junit.Test)64 SubjectAware (com.github.sdorra.shiro.SubjectAware)46 Test (org.junit.jupiter.api.Test)41 JsonNode (com.fasterxml.jackson.databind.JsonNode)29 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)24 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)17 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)16 DisplayUser (sonia.scm.user.DisplayUser)16 User (sonia.scm.user.User)16 MockHttpResponse (org.jboss.resteasy.mock.MockHttpResponse)14 NamespaceAndName (sonia.scm.repository.NamespaceAndName)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 Repository (sonia.scm.repository.Repository)9 Comment (com.cloudogu.scm.review.comment.service.Comment)8 BranchRevisionResolver (com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 URISyntaxException (java.net.URISyntaxException)8 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)8 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)8