Search in sources :

Example 1 with TestInfo

use of org.junit.jupiter.api.TestInfo in project harvest-client by 3AP-AG.

the class ProjectAssignmentsApiImplTest method listSelf.

@Test
void listSelf(TestInfo testInfo) {
    Project project = null;
    try {
        final Project tempProject = harvest.projects().create(ImmutableProject.builder().name("Project for " + testInfo.getDisplayName()).billBy(Project.BillingMethod.PROJECT).budgetBy(Project.BudgetMethod.HOURS_PER_PROJECT).billable(false).client(ExistingData.getInstance().getClientReference()).build());
        project = tempProject;
        User self = harvest.users().getSelf();
        // remove self from tempProject
        harvest.userAssignments().list(project, new UserAssignmentFilter()).stream().filter(ua -> ua.getUser().getId().equals(self.getId())).forEach(ua -> harvest.userAssignments().delete(tempProject, ua));
        List<ProjectAssignment> projectAssignments = projectAssignmentsApi.listSelf();
        assertThat(projectAssignments).isNotEmpty();
        assertThat(projectAssignments).extracting("project").extracting("id").doesNotContain(tempProject.getId());
    } finally {
        if (project != null) {
            harvest.projects().delete(project);
        }
    }
}
Also used : HarvestTest(ch.aaap.harvestclient.HarvestTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Instant(java.time.Instant) TestInfo(org.junit.jupiter.api.TestInfo) TestSetupUtil(util.TestSetupUtil) Test(org.junit.jupiter.api.Test) Harvest(ch.aaap.harvestclient.core.Harvest) List(java.util.List) Reference(ch.aaap.harvestclient.domain.reference.Reference) ProjectAssignmentsApi(ch.aaap.harvestclient.api.ProjectAssignmentsApi) Project(ch.aaap.harvestclient.domain.Project) ImmutableProject(ch.aaap.harvestclient.domain.ImmutableProject) User(ch.aaap.harvestclient.domain.User) UserAssignmentFilter(ch.aaap.harvestclient.api.filter.UserAssignmentFilter) ProjectAssignment(ch.aaap.harvestclient.domain.ProjectAssignment) ExistingData(util.ExistingData) Project(ch.aaap.harvestclient.domain.Project) ImmutableProject(ch.aaap.harvestclient.domain.ImmutableProject) User(ch.aaap.harvestclient.domain.User) ProjectAssignment(ch.aaap.harvestclient.domain.ProjectAssignment) UserAssignmentFilter(ch.aaap.harvestclient.api.filter.UserAssignmentFilter) HarvestTest(ch.aaap.harvestclient.HarvestTest) Test(org.junit.jupiter.api.Test)

Example 2 with TestInfo

use of org.junit.jupiter.api.TestInfo in project component-runtime by Talend.

the class ComponentResourceTest method getDependency.

@Test
void getDependency(final TestInfo info, final TemporaryFolder folder) {
    final Function<String, File> download = id -> {
        final InputStream stream = base.path("component/dependency/{id}").resolveTemplate("id", id).request(APPLICATION_OCTET_STREAM_TYPE).get(InputStream.class);
        final File file = new File(folder.getRoot(), info.getTestMethod().get().getName() + ".jar");
        try (final OutputStream outputStream = new FileOutputStream(file)) {
            IO.copy(stream, outputStream);
        } catch (final IOException e) {
            throw new IllegalStateException(e);
        }
        return file;
    };
    final Consumer<File> jarValidator = file -> {
        assertTrue(file.exists());
        try (final JarFile jar = new JarFile(file)) {
            assertTrue(jar.entries().hasMoreElements());
        } catch (final IOException e) {
            fail(e.getMessage());
        }
    };
    final File zipLock = download.apply("org.apache.tomee:ziplock:jar:7.0.4");
    jarValidator.accept(zipLock);
    final File component = download.apply(client.getJdbcId());
    jarValidator.accept(component);
}
Also used : MonoMeecrowaveConfig(org.apache.meecrowave.junit5.MonoMeecrowaveConfig) JarFile(java.util.jar.JarFile) Collections.singletonList(java.util.Collections.singletonList) ComponentDetail(org.talend.sdk.component.server.front.model.ComponentDetail) MediaType(javax.ws.rs.core.MediaType) Link(org.talend.sdk.component.server.front.model.Link) ActionReference(org.talend.sdk.component.server.front.model.ActionReference) Map(java.util.Map) ComponentDetailList(org.talend.sdk.component.server.front.model.ComponentDetailList) Predicate(java.util.function.Predicate) Collection(java.util.Collection) WebsocketClient(org.talend.sdk.component.server.test.websocket.WebsocketClient) DependencyDefinition(org.talend.sdk.component.server.front.model.DependencyDefinition) StandardCharsets(java.nio.charset.StandardCharsets) TestInfo(org.junit.jupiter.api.TestInfo) GenericType(javax.ws.rs.core.GenericType) Test(org.junit.jupiter.api.Test) Base64(java.util.Base64) List(java.util.List) APPLICATION_OCTET_STREAM_TYPE(javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM_TYPE) ComponentClient(org.talend.sdk.component.server.test.ComponentClient) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TemporaryFolder(org.talend.sdk.component.junit.base.junit5.TemporaryFolder) PropertyValidation(org.talend.sdk.component.server.front.model.PropertyValidation) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Dependencies(org.talend.sdk.component.server.front.model.Dependencies) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) Entity.entity(javax.ws.rs.client.Entity.entity) DeploymentException(javax.websocket.DeploymentException) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) WithTemporaryFolder(org.talend.sdk.component.junit.base.junit5.WithTemporaryFolder) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OutputStream(java.io.OutputStream) Iterator(java.util.Iterator) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ComponentIndex(org.talend.sdk.component.server.front.model.ComponentIndex) ComponentIndices(org.talend.sdk.component.server.front.model.ComponentIndices) File(java.io.File) Consumer(java.util.function.Consumer) IO(org.apache.ziplock.IO) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) WebTarget(javax.ws.rs.client.WebTarget) Comparator(java.util.Comparator) InputStream(java.io.InputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 3 with TestInfo

use of org.junit.jupiter.api.TestInfo in project component-runtime by Talend.

the class StudioInstallerTest method run.

@Test
void run(final TemporaryFolder temporaryFolder, final TestInfo info) throws IOException {
    final String testName = info.getTestMethod().get().getName();
    final File studioHome = new File(temporaryFolder.getRoot(), testName);
    final File configuration = org.apache.ziplock.Files.mkdir(new File(studioHome, "configuration"));
    try (final Writer configIni = new FileWriter(new File(configuration, "config.ini"))) {
    // no-op
    }
    final File artifact = new File(temporaryFolder.getRoot(), testName + ".jar");
    try (final JarOutputStream out = new JarOutputStream(new FileOutputStream(artifact))) {
        out.putNextEntry(new JarEntry("META-INF/MANIFEST.MF"));
        out.closeEntry();
    }
    final StudioInstaller installer = new StudioInstaller("gtest:atest:1.0-SNAPSHOT", studioHome, singletonMap("gtest:atest:1.0-SNAPSHOT", artifact), new Log() {

        @Override
        public void debug(final String s) {
            log.info(s);
        }

        @Override
        public void error(final String s) {
            log.error(s);
        }

        @Override
        public void info(final String s) {
            log.info(s);
        }
    });
    installer.run();
    final File backup = new File(studioHome, "configuration/backup");
    {
        assertTrue(backup.exists());
        assertEquals(1, backup.listFiles((dir, name) -> name.startsWith("config.ini")).length);
        assertSetup(studioHome);
    }
    installer.run();
    {
        assertSetup(studioHome);
        // 1 again cause already here so no other backup
        assertEquals(1, backup.listFiles((dir, name) -> name.startsWith("config.ini")).length);
    }
}
Also used : Files(java.nio.file.Files) FileWriter(java.io.FileWriter) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) TestInfo(org.junit.jupiter.api.TestInfo) Test(org.junit.jupiter.api.Test) JarEntry(java.util.jar.JarEntry) Slf4j(lombok.extern.slf4j.Slf4j) Collections.singleton(java.util.Collections.singleton) WithTemporaryFolder(org.talend.sdk.component.junit.base.junit5.WithTemporaryFolder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TemporaryFolder(org.talend.sdk.component.junit.base.junit5.TemporaryFolder) Writer(java.io.Writer) Collections.singletonMap(java.util.Collections.singletonMap) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JarOutputStream(java.util.jar.JarOutputStream) Collectors.toSet(java.util.stream.Collectors.toSet) FileWriter(java.io.FileWriter) FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) JarEntry(java.util.jar.JarEntry) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 TestInfo (org.junit.jupiter.api.TestInfo)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 List (java.util.List)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 TemporaryFolder (org.talend.sdk.component.junit.base.junit5.TemporaryFolder)2 WithTemporaryFolder (org.talend.sdk.component.junit.base.junit5.WithTemporaryFolder)2 HarvestTest (ch.aaap.harvestclient.HarvestTest)1 ProjectAssignmentsApi (ch.aaap.harvestclient.api.ProjectAssignmentsApi)1 UserAssignmentFilter (ch.aaap.harvestclient.api.filter.UserAssignmentFilter)1 Harvest (ch.aaap.harvestclient.core.Harvest)1 ImmutableProject (ch.aaap.harvestclient.domain.ImmutableProject)1 Project (ch.aaap.harvestclient.domain.Project)1 ProjectAssignment (ch.aaap.harvestclient.domain.ProjectAssignment)1 User (ch.aaap.harvestclient.domain.User)1 Reference (ch.aaap.harvestclient.domain.reference.Reference)1 FileWriter (java.io.FileWriter)1