Search in sources :

Example 1 with ProjectEx

use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.

the class ProjectRequestTest method memoryTest.

// @Test
public void memoryTest() throws InterruptedException {
    final ProjectRequest request = new ProjectRequest();
    request.setInTests(myProjectFinder, myBranchFinder, myBeanContext);
    final String locator = "archived:false,affectedProject:_Root";
    final String fields = "count,project(id,internalId,name,parentProjectId,archived,readOnlyUI,buildTypes(buildType(id,paused,internalId,projectId,name,type,description)),description)";
    Queue<Pair<Integer, ProjectEx>> q = new ArrayDeque<>();
    q.add(new Pair<>(0, myProject));
    final int max = 2;
    final int children = 4;
    int counter = 0;
    while (!q.isEmpty()) {
        Pair<Integer, ProjectEx> p = q.poll();
        String prefix = "Bt" + StringUtils.repeat('a', 10 * p.getFirst());
        for (int i = 0; i < children; i++) {
            ProjectEx c = myFixture.createProject("z-" + p.first + "-" + counter++, p.second);
            if (p.first < max) {
                q.add(new Pair<>(p.first + 1, c));
            }
            for (int j = 0; j < children * 4; j++) c.createBuildType(prefix + j);
        }
    }
    System.out.println(counter + " projects created.");
    Thread[] ts = new Thread[100];
    for (int i = 0; i < ts.length; i++) {
        final int threadIdx = i;
        ts[i] = new Thread(() -> {
            new RestContext(z -> null).run(() -> {
                for (int j = 0; j < 100; j++) {
                    final PagedSearchResult<SProject> result = myProjectFinder.getItems(locator);
                    Projects projects = new Projects(result.myEntries, null, new Fields(fields), myBeanContext);
                    projects.projects.stream().flatMap(p -> p.buildTypes.buildTypes.stream()).forEach(bt -> {
                        bt.getId();
                        bt.isPaused();
                        bt.getInternalId();
                        bt.getProjectId();
                        bt.getName();
                        bt.getType();
                        bt.getDescription();
                    });
                    System.out.println(String.format("Finished %d requests in thread %d", j, threadIdx));
                }
                return null;
            });
        });
        ts[i].start();
    }
    for (Thread t : ts) t.join();
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) java.util(java.util) Test(org.testng.annotations.Test) PagedSearchResult(jetbrains.buildServer.server.rest.data.PagedSearchResult) SProjectFeatureDescriptor(jetbrains.buildServer.serverSide.SProjectFeatureDescriptor) StringUtils(org.apache.commons.lang3.StringUtils) Branch(jetbrains.buildServer.server.rest.model.build.Branch) Projects(jetbrains.buildServer.server.rest.model.project.Projects) Option(jetbrains.buildServer.util.Option) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) CollectionsUtil(jetbrains.buildServer.util.CollectionsUtil) RestContext(jetbrains.buildServer.server.rest.data.RestContext) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) ProjectFeatureDescriptorFactory(jetbrains.buildServer.serverSide.impl.ProjectFeatureDescriptorFactory) MockVcsSupport(jetbrains.buildServer.serverSide.impl.MockVcsSupport) OperationRequestor(jetbrains.buildServer.vcs.OperationRequestor) BuildFinderTestBase(jetbrains.buildServer.server.rest.data.BuildFinderTestBase) Branches(jetbrains.buildServer.server.rest.model.build.Branches) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) BeforeMethod(org.testng.annotations.BeforeMethod) RepositoryStateData.createVersionState(jetbrains.buildServer.vcs.RepositoryStateData.createVersionState) Util.map(jetbrains.buildServer.util.Util.map) ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) BuildTypeEx(jetbrains.buildServer.serverSide.BuildTypeEx) Pair(com.intellij.openapi.util.Pair) SProject(jetbrains.buildServer.serverSide.SProject) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) Projects(jetbrains.buildServer.server.rest.model.project.Projects) RestContext(jetbrains.buildServer.server.rest.data.RestContext) ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) Fields(jetbrains.buildServer.server.rest.model.Fields) PagedSearchResult(jetbrains.buildServer.server.rest.data.PagedSearchResult) Pair(com.intellij.openapi.util.Pair)

Example 2 with ProjectEx

use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.

the class ProjectRequestTest method testProjectFeaturesParameters.

@Test
void testProjectFeaturesParameters() {
    ProjectEx project10 = createProject("project10", "project10");
    SProjectFeatureDescriptor feature10 = myFixture.getSingletonService(ProjectFeatureDescriptorFactory.class).createNewProjectFeature("feature_type", CollectionsUtil.asMap("a", "b"), project10.getProjectId());
    project10.addFeature(feature10);
    {
        String newValue = myRequest.getFeatures("id:" + project10.getExternalId()).getParametersSubResource(feature10.getId(), "$long").setParameterValue("a", "B");
        assertEquals("B", newValue);
        assertEquals(1, project10.getAvailableFeatures().size());
        assertEquals("B", project10.findFeatureById(feature10.getId()).getParameters().get("a"));
    }
    {
        String newValue = myRequest.getFeatures("id:" + project10.getExternalId()).getParametersSubResource("id:" + feature10.getId(), "$long").setParameterValue("a", "X");
        assertEquals("X", newValue);
        assertEquals(1, project10.getAvailableFeatures().size());
        assertEquals("X", project10.findFeatureById(feature10.getId()).getParameters().get("a"));
        assertEquals(1, project10.findFeatureById(feature10.getId()).getParameters().size());
    }
    {
        String newValue = myRequest.getFeatures("id:" + project10.getExternalId()).getParametersSubResource("id:" + feature10.getId(), "$long").setParameterValue("b", "Y");
        assertEquals("Y", newValue);
        assertEquals(1, project10.getAvailableFeatures().size());
        assertEquals(2, project10.findFeatureById(feature10.getId()).getParameters().size());
        assertEquals("Y", project10.findFeatureById(feature10.getId()).getParameters().get("b"));
    }
    {
        myRequest.getFeatures("id:" + project10.getExternalId()).getParametersSubResource("id:" + feature10.getId(), "$long").deleteParameter("b");
        assertEquals(1, project10.getAvailableFeatures().size());
        assertEquals(1, project10.findFeatureById(feature10.getId()).getParameters().size());
        assertEquals(null, project10.findFeatureById(feature10.getId()).getParameters().get("b"));
        assertEquals("X", project10.findFeatureById(feature10.getId()).getParameters().get("a"));
    }
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) ProjectFeatureDescriptorFactory(jetbrains.buildServer.serverSide.impl.ProjectFeatureDescriptorFactory) SProjectFeatureDescriptor(jetbrains.buildServer.serverSide.SProjectFeatureDescriptor) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 3 with ProjectEx

use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.

the class VcsRootInstanceFinderTest method testVersionedSettingsInstances.

@Test
public void testVersionedSettingsInstances() throws Exception {
    myFixture.registerVcsSupport("svn");
    final ProjectEx project10 = getRootProject().createProject("project10", "Project name 10");
    final ProjectEx project20 = project10.createProject("project20", "Project name 20");
    final ProjectEx project30 = project20.createProject("project30", "Project name 30");
    final ProjectEx project40 = project30.createProject("project40", "Project name 40");
    final ProjectEx project50 = project40.createProject("project50", "Project name 50");
    final ProjectEx project60 = project40.createProject("project60", "Project name 60");
    final SVcsRoot vcsRoot20 = project20.createVcsRoot("svn", "id10", "VCS root 10 name");
    vcsRoot20.setProperties(CollectionsUtil.asMap("aaa", "%param%"));
    final SVcsRoot vcsRoot30 = project20.createVcsRoot("svn", "id30", "id30");
    ProjectFeatureDescriptorFactory projectFeatureFactory = myFixture.getSingletonService(ProjectFeatureDescriptorFactory.class);
    Map<String, String> params = CollectionsUtil.asMap("buildSettings", "ALWAYS_USE_CURRENT", "rootId", vcsRoot20.getExternalId(), "showChanges", "false");
    SProjectFeatureDescriptor featureDescriptor30 = projectFeatureFactory.createNewProjectFeature("versionedSettings", params, project30.getProjectId());
    project30.addFeature(featureDescriptor30);
    Map<String, String> params2 = CollectionsUtil.asMap("buildSettings", "ALWAYS_USE_CURRENT", "rootId", vcsRoot20.getExternalId(), "showChanges", "true");
    SProjectFeatureDescriptor featureDescriptor40 = projectFeatureFactory.createNewProjectFeature("versionedSettings", params2, project40.getProjectId());
    project30.addFeature(featureDescriptor40);
    Map<String, String> params3 = CollectionsUtil.asMap("enabled", "false");
    SProjectFeatureDescriptor featureDescriptor60 = projectFeatureFactory.createNewProjectFeature("versionedSettings", params3, project60.getProjectId());
    project60.addFeature(featureDescriptor60);
    VersionedSettingsManager versionedSettingsManager = myFixture.getSingletonService(VersionedSettingsManager.class);
    {
        VcsRootInstance versionedSettingsVcsRoot_p30 = versionedSettingsManager.getVersionedSettingsVcsRootInstance(project30);
        check(null, versionedSettingsVcsRoot_p30);
        check("affectedProject:(id:" + project20.getExternalId() + ")", versionedSettingsVcsRoot_p30);
        check("affectedProject:(id:" + project30.getExternalId() + ")", versionedSettingsVcsRoot_p30);
        check("affectedProject:(id:" + project40.getExternalId() + ")", versionedSettingsVcsRoot_p30);
    }
    project20.addParameter(new SimpleParameter("param", "p20"));
    project30.addParameter(new SimpleParameter("param", "p30"));
    project40.addParameter(new SimpleParameter("param", "p40"));
    BuildTypeEx p40_bt10 = project40.createBuildType("p40_bt10");
    p40_bt10.addParameter(new SimpleParameter("param", "bt"));
    BuildTypeEx p40_bt20 = project40.createBuildType("p40_bt20");
    BuildTypeEx p40_bt30 = project40.createBuildType("p40_bt30");
    {
        VcsRootInstance versionedSettingsVcsRoot_p30 = versionedSettingsManager.getVersionedSettingsVcsRootInstance(project30);
        VcsRootInstance versionedSettingsVcsRoot_p40 = versionedSettingsManager.getVersionedSettingsVcsRootInstance(project40);
        VcsRootInstance btInstance10 = attachVcsRoot(p40_bt10, vcsRoot20);
        VcsRootInstance btInstance20 = attachVcsRoot(p40_bt20, vcsRoot20);
        VcsRootInstance btInstance30 = attachVcsRoot(p40_bt20, vcsRoot30);
        assert btInstance20.equals(versionedSettingsVcsRoot_p40);
        check(null, versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, btInstance10, btInstance30);
        check("property:(name:aaa,value:p30)", versionedSettingsVcsRoot_p30);
        check("buildType:(id:" + p40_bt10.getExternalId() + ")", btInstance10);
        check("buildType:(id:" + p40_bt20.getExternalId() + ")", versionedSettingsVcsRoot_p40, btInstance30);
        check("buildType:(id:" + p40_bt30.getExternalId() + ")");
        check("buildType:(id:" + p40_bt10.getExternalId() + "),versionedSettings:any", versionedSettingsVcsRoot_p40, btInstance10);
        check("buildType:(id:" + p40_bt10.getExternalId() + "),versionedSettings:false", btInstance10);
        check("buildType:(id:" + p40_bt10.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p40);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),versionedSettings:any", versionedSettingsVcsRoot_p40, btInstance30);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),versionedSettings:false", versionedSettingsVcsRoot_p40, btInstance30);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p40);
        check("buildType:(id:" + p40_bt30.getExternalId() + "),versionedSettings:any", versionedSettingsVcsRoot_p40);
        check("buildType:(id:" + p40_bt30.getExternalId() + "),versionedSettings:false");
        check("buildType:(id:" + p40_bt30.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p40);
        check("buildType:(id:" + p40_bt10.getExternalId() + "),vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:false", btInstance10);
        check("buildType:(id:" + p40_bt10.getExternalId() + "),vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:any", versionedSettingsVcsRoot_p40, btInstance10);
        check("buildType:(id:" + p40_bt10.getExternalId() + "),vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p40);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:false", versionedSettingsVcsRoot_p40);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:any", versionedSettingsVcsRoot_p40);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p40);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),vcsRoot:(id:" + vcsRoot30.getExternalId() + "),versionedSettings:false", btInstance30);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),vcsRoot:(id:" + vcsRoot30.getExternalId() + "),versionedSettings:any", btInstance30);
        check("buildType:(id:" + p40_bt20.getExternalId() + "),vcsRoot:(id:" + vcsRoot30.getExternalId() + "),versionedSettings:true");
        check("vcsRoot:(id:" + vcsRoot20.getExternalId() + ")", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, btInstance10);
        check("vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40);
        check("vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:false", versionedSettingsVcsRoot_p40, btInstance10);
        check("vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:any", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, btInstance10);
        check("buildType:(count:1000)", versionedSettingsVcsRoot_p40, btInstance10, btInstance30);
        project50.addParameter(new SimpleParameter("param", "p50"));
        VcsRootInstance versionedSettingsVcsRoot_p50 = versionedSettingsManager.getVersionedSettingsVcsRootInstance(project50);
        check(null, versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, btInstance10, btInstance30, versionedSettingsVcsRoot_p50);
        check("vcsRoot:(id:" + vcsRoot20.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, versionedSettingsVcsRoot_p50);
        check("versionedSettings:true", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, versionedSettingsVcsRoot_p50);
        check("buildType:(count:1000)", versionedSettingsVcsRoot_p40, btInstance10, btInstance30);
        // versionedSettingsVcsRoot_p50 not included as no configs in the project
        check("buildType:(count:1000),versionedSettings:any", versionedSettingsVcsRoot_p40, btInstance10, btInstance30);
        check("item:(buildType:(count:1000),versionedSettings:false),item:(versionedSettings:true)", versionedSettingsVcsRoot_p40, btInstance10, btInstance30, // so far sorting does not work for "or"
        versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p50);
        // has showChanges=false in versioned settings
        BuildTypeEx p30_bt10 = project30.createBuildType("p30_bt10");
        check("buildType:(id:" + p30_bt10.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p30);
        p40_bt20.removeVcsRoot(vcsRoot30);
        project50.removeParameter("param");
        // check("project:(id:" + project20.getExternalId() + ")");
        check("project:(id:" + project30.getExternalId() + ")", versionedSettingsVcsRoot_p30);
        check("project:(id:" + project40.getExternalId() + ")", versionedSettingsVcsRoot_p40);
        check("project:(id:" + project50.getExternalId() + ")", versionedSettingsVcsRoot_p40);
        check("project:(id:" + project60.getExternalId() + ")");
        check("affectedProject:(id:" + project20.getExternalId() + ")", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, btInstance10);
        check("affectedProject:(id:" + project30.getExternalId() + ")", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, btInstance10);
        check("affectedProject:(id:" + project40.getExternalId() + ")", versionedSettingsVcsRoot_p40, btInstance10);
        check("affectedProject:(id:" + project20.getExternalId() + "),versionedSettings:any", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40, btInstance10);
        check("affectedProject:(id:" + project20.getExternalId() + "),versionedSettings:false", versionedSettingsVcsRoot_p40, btInstance10);
        check("affectedProject:(id:" + project20.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p30, versionedSettingsVcsRoot_p40);
        final ProjectEx project70 = project40.createProject("project70", "Project name 70");
        project70.addParameter(new SimpleParameter("param", "bt"));
        VcsRootInstance versionedSettingsVcsRoot_p70 = versionedSettingsManager.getVersionedSettingsVcsRootInstance(project70);
        assert versionedSettingsVcsRoot_p70 != null;
        assert versionedSettingsVcsRoot_p70.equals(btInstance10);
        check("buildType:(id:" + p40_bt10.getExternalId() + ")", btInstance10);
        check("project:(id:" + project40.getExternalId() + ")", versionedSettingsVcsRoot_p40);
        check("project:(id:" + project70.getExternalId() + ")", btInstance10);
        check("project:(id:" + project70.getExternalId() + "),versionedSettings:true", btInstance10);
        check("project:(id:" + project70.getExternalId() + "),versionedSettings:false");
        check("affectedProject:(id:" + project40.getExternalId() + ")", versionedSettingsVcsRoot_p40, btInstance10);
        check("affectedProject:(id:" + project40.getExternalId() + "),versionedSettings:any", versionedSettingsVcsRoot_p40, btInstance10);
        check("affectedProject:(id:" + project40.getExternalId() + "),versionedSettings:false", btInstance20, btInstance10);
        check("affectedProject:(id:" + project40.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p40, btInstance10);
        check("affectedProject:(id:" + project70.getExternalId() + "),versionedSettings:false");
        check("affectedProject:(id:" + project70.getExternalId() + "),versionedSettings:true", versionedSettingsVcsRoot_p70);
    }
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) ProjectFeatureDescriptorFactory(jetbrains.buildServer.serverSide.impl.ProjectFeatureDescriptorFactory) VersionedSettingsManager(jetbrains.buildServer.serverSide.versionedSettings.VersionedSettingsManager) Test(org.testng.annotations.Test)

Example 4 with ProjectEx

use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.

the class VcsRootInstanceFinderTest method testRepositoryIdString.

@SuppressWarnings("ConstantConditions")
@Test
public void testRepositoryIdString() throws Exception {
    MockVcsSupport svn = myFixture.registerVcsSupport("svn");
    svn.addCustomVcsExtension(VcsPersonalSupport.class, new VcsPersonalSupport() {

        @NotNull
        @Override
        public Collection<String> mapFullPath(@NotNull final VcsRootEntry rootEntry, @NotNull final String fullPath) throws VcsException {
            String prefix = rootEntry.getProperties().get("prefix");
            if (prefix != null && fullPath.startsWith(prefix))
                return Collections.singletonList(fullPath.substring(prefix.length()));
            return Collections.emptyList();
        }
    });
    svn.addCustomVcsExtension(VcsClientMappingProvider.class, new VcsRootBasedMappingProvider() {

        @Override
        public Collection<VcsClientMapping> getClientMapping(@NotNull final VcsRoot vcsRoot) throws VcsException {
            String prefix = vcsRoot.getProperties().get("prefix");
            if (prefix != null)
                return Collections.singletonList(new VcsClientMapping(prefix, ""));
            return Collections.emptyList();
        }
    });
    myFixture.registerVcsSupport("custom");
    final ProjectEx project10 = getRootProject().createProject("project10", "Project name 10");
    final SVcsRoot vcsRoot10 = project10.createVcsRoot("svn", "id10", "VCS root 10 name");
    vcsRoot10.setProperties(CollectionsUtil.asMap("url", "22", "prefix", "000000-0000-1111-000000000001|trunk/path1"));
    final SVcsRoot vcsRoot12 = project10.createVcsRoot("svn", "id12", "VCS root 12 name");
    vcsRoot12.setProperties(CollectionsUtil.asMap("url", "", "prefix", "000000-0000-1111-000000000001|trunk/path2"));
    final SVcsRoot vcsRoot15 = project10.createVcsRoot("custom", "id15", "VCS root 15 name");
    vcsRoot15.setProperties(CollectionsUtil.asMap("url", "", "aaa", "3"));
    final SBuildType bt10 = project10.createBuildType("id10", "name 10");
    VcsRootInstance vInstance10 = attachVcsRoot(bt10, vcsRoot10);
    VcsRootInstance vInstance20 = attachVcsRoot(bt10, vcsRoot12);
    bt10.setCheckoutRules(vcsRoot10, new CheckoutRules("+:aaa=>bbb"));
    check("repositoryIdString:xxx");
    // pre-TeamCity 10 behavior
    check("repositoryIdString:000000-0000-1111-000000000001|trunk/path1", vInstance10);
    // pre-TeamCity 10 behavior
    check("repositoryIdString:000000-0000-1111-000000000001|trunk/path1/aaa", vInstance10);
    check("repositoryIdString:svn://000000-0000-1111-000000000001|trunk/path1", vInstance10);
    check("repositoryIdString:svn://000000-0000-1111-000000000001|trunk/path1/aaa", vInstance10);
    check("repositoryIdString:svn://000000-0000-1111-000000000001|trunk/path2/aaa", vInstance20);
    check("repositoryIdString:svn://000000-0000-1111-000000000001|trunk2");
    check("repositoryIdString:svn://000000-0000-1111-000000000001|trunk/path9");
    check("repositoryIdString:svn://000000-0000-1111-000000000002|trunk/path1");
    // does not work for now    check("repositoryIdString:svn://000000-0000-1111-000000000001|", vInstance10, vInstance20);
    check("repositoryIdString:svn://000000-0000-1111-000000000001|trunk", vInstance10, vInstance20);
    check("repositoryIdString:svn://000000-0000-1111-000000000001|trunk/path");
}
Also used : NotNull(org.jetbrains.annotations.NotNull) ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) MockVcsSupport(jetbrains.buildServer.serverSide.impl.MockVcsSupport) Collection(java.util.Collection) Test(org.testng.annotations.Test)

Example 5 with ProjectEx

use of jetbrains.buildServer.serverSide.impl.ProjectEx in project teamcity-rest by JetBrains.

the class VcsRootInstanceFinderTest method testStatusFiltering.

@SuppressWarnings("ConstantConditions")
@Test
public void testStatusFiltering() throws Exception {
    final MockTimeService time = new MockTimeService(Dates.now().getTime());
    myServer.setTimeService(time);
    myFixture.registerVcsSupport("svn");
    final ProjectEx project10 = getRootProject().createProject("project10", "Project name 10");
    final SVcsRoot vcsRoot = getRootProject().createVcsRoot("svn", "id1", "VCS root 1 name");
    final SBuildType bt = project10.createBuildType("id1", "name 1");
    attachVcsRoot(bt, vcsRoot);
    final SVcsRoot vcsRoot2 = getRootProject().createVcsRoot("svn", "id2", "VCS root 2 name");
    final SBuildType bt2 = project10.createBuildType("id2", "name 2");
    attachVcsRoot(bt2, vcsRoot2);
    assertEquals(2, getFinder().getItems("status:not_monitored").myEntries.size());
    assertEquals(0, getFinder().getItems("status:scheduled").myEntries.size());
    assertEquals(0, getFinder().getItems("status:started").myEntries.size());
    assertEquals(0, getFinder().getItems("status:finished").myEntries.size());
    assertEquals(0, getFinder().getItems("status:unknown").myEntries.size());
    ((VcsRootInstanceEx) bt.getVcsRootInstances().get(0)).setStatus(VcsRootStatus.Type.FINISHED);
    assertEquals(1, getFinder().getItems("status:not_monitored").myEntries.size());
    assertEquals(0, getFinder().getItems("status:scheduled").myEntries.size());
    assertEquals(0, getFinder().getItems("status:started").myEntries.size());
    assertEquals(1, getFinder().getItems("status:finished").myEntries.size());
    assertEquals(0, getFinder().getItems("status:unknown").myEntries.size());
    ((VcsRootInstanceEx) bt2.getVcsRootInstances().get(0)).setStatus(VcsRootStatus.Type.STARTED);
    assertEquals(0, getFinder().getItems("status:not_monitored").myEntries.size());
    assertEquals(0, getFinder().getItems("status:scheduled").myEntries.size());
    assertEquals(1, getFinder().getItems("status:started").myEntries.size());
    assertEquals(1, getFinder().getItems("status:finished").myEntries.size());
    assertEquals(0, getFinder().getItems("status:unknown").myEntries.size());
    checkExceptionOnItemsSearch(BadRequestException.class, "status:aaa");
    assertEquals(1, getFinder().getItems("status:(current:(status:started))").myEntries.size());
    ((VcsRootInstanceEx) bt2.getVcsRootInstances().get(0)).setStatus(VcsRootStatus.Type.FINISHED);
    assertEquals(2, getFinder().getItems("status:(current:(status:finished))").myEntries.size());
    assertEquals(1, getFinder().getItems("status:(previous:(status:started))").myEntries.size());
    time.jumpTo(10);
    assertEquals(0, getFinder().getItems("status:(current:(timestamp:-2s))").myEntries.size());
    assertEquals(2, getFinder().getItems("status:(current:(timestamp:-20s))").myEntries.size());
    assertEquals(0, getFinder().getItems("checkingForChangesFinishDate:-2s").myEntries.size());
    assertEquals(2, getFinder().getItems("checkingForChangesFinishDate:-20s").myEntries.size());
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) MockTimeService(jetbrains.buildServer.MockTimeService) Test(org.testng.annotations.Test)

Aggregations

ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)52 Test (org.testng.annotations.Test)42 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)16 SUser (jetbrains.buildServer.users.SUser)10 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)8 BuildTypeEx (jetbrains.buildServer.serverSide.BuildTypeEx)7 MockVcsSupport (jetbrains.buildServer.serverSide.impl.MockVcsSupport)7 BuildType (jetbrains.buildServer.server.rest.model.buildType.BuildType)6 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)6 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)5 Fields (jetbrains.buildServer.server.rest.model.Fields)5 TestName (jetbrains.buildServer.tests.TestName)5 ApiOperation (io.swagger.annotations.ApiOperation)4 SUserGroup (jetbrains.buildServer.groups.SUserGroup)4 ProjectRequestTest (jetbrains.buildServer.server.rest.request.ProjectRequestTest)4 Mutes (jetbrains.buildServer.server.rest.model.problem.Mutes)3 SFinishedBuild (jetbrains.buildServer.serverSide.SFinishedBuild)3 SProject (jetbrains.buildServer.serverSide.SProject)3 STest (jetbrains.buildServer.serverSide.STest)3 Permissions (jetbrains.buildServer.serverSide.auth.Permissions)3