Search in sources :

Example 11 with Tags

use of org.ovirt.engine.core.common.businessentities.Tags in project ovirt-engine by oVirt.

the class TagsDirectorTest method testUpdateChildren.

@Test
public void testUpdateChildren() {
    Tags tag = createTag("tag1", "desc1");
    tagsDirector.addTag(tag);
    tag.setTagName("booboo");
    tagsDirector.updateTag(tag);
    Tags rootTag = tagsDirector.getRootTag();
    tag = rootTag.getChildren().get(0);
    assertEquals("booboo", tag.getTagName());
}
Also used : Tags(org.ovirt.engine.core.common.businessentities.Tags) Test(org.junit.Test)

Example 12 with Tags

use of org.ovirt.engine.core.common.businessentities.Tags in project ovirt-engine by oVirt.

the class TagsDirectorTest method testMoveTag.

@Test
public void testMoveTag() {
    // let's have two top level tag under root
    Tags level1obj1 = createTag("level1obj1", "");
    level1obj1.setTagId(Guid.newGuid());
    level1obj1.setParentId(tagsDirector.getRootTag().getTagId());
    tagsDirector.addTag(level1obj1);
    Tags level1obj2 = createTag("level1obj2", "");
    level1obj2.setTagId(Guid.newGuid());
    level1obj2.setParentId(tagsDirector.getRootTag().getTagId());
    tagsDirector.addTag(level1obj2);
    // now none of these should have any children
    assertEquals(0, tagsDirector.getTagById(level1obj1.getTagId()).getChildren().size());
    assertEquals(0, tagsDirector.getTagById(level1obj2.getTagId()).getChildren().size());
    // now let's add a child tag o the first top level tag
    Tags level2obj1 = createTag("level2obj1", "");
    level2obj1.setTagId(Guid.newGuid());
    level2obj1.setParentId(level1obj1.getTagId());
    tagsDirector.addTag(level2obj1);
    // now check the number of children
    assertEquals(1, tagsDirector.getTagById(level1obj1.getTagId()).getChildren().size());
    assertEquals(0, tagsDirector.getTagById(level1obj2.getTagId()).getChildren().size());
    // should be all right so far.
    // now let's do the trick: move the second level tag to under the other first level tag
    tagsDirector.moveTag(level2obj1.getTagId(), level1obj2.getTagId());
    // and now let's recheck, the first top level should have 0 children, the second should have 1
    assertEquals(0, tagsDirector.getTagById(level1obj1.getTagId()).getChildren().size());
    assertEquals(1, tagsDirector.getTagById(level1obj2.getTagId()).getChildren().size());
}
Also used : Tags(org.ovirt.engine.core.common.businessentities.Tags) Test(org.junit.Test)

Example 13 with Tags

use of org.ovirt.engine.core.common.businessentities.Tags in project ovirt-engine by oVirt.

the class TagsDirectorTest method testGetAllTags.

@Test
public void testGetAllTags() {
    ArrayList<Tags> allTags = tagsDirector.getAllTags();
    assertEquals(0, allTags.size());
    Tags tag = createTag("tag1", "desc1");
    tagsDirector.addTag(tag);
    allTags = tagsDirector.getAllTags();
    assertEquals(1, allTags.size());
    tag = createTag("tag2", "desc2");
    tagsDirector.addTag(tag);
    allTags = tagsDirector.getAllTags();
    assertEquals(2, allTags.size());
}
Also used : Tags(org.ovirt.engine.core.common.businessentities.Tags) Test(org.junit.Test)

Example 14 with Tags

use of org.ovirt.engine.core.common.businessentities.Tags in project ovirt-engine by oVirt.

the class BackendTagsResourceTest method testAddTagNoParent.

@Test
public void testAddTagNoParent() throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    Tags entity = getEntity(0);
    entity.setParentId(Guid.Empty);
    setUpCreationExpectations(ActionType.AddTag, TagsOperationParameters.class, new String[] { "Tag.TagName", "Tag.ParentId" }, new Object[] { NAMES[0], Guid.Empty }, true, true, null, QueryType.GetTagByTagName, NameQueryParameters.class, new String[] { "Name" }, new Object[] { NAMES[0] }, entity);
    Tag model = getModel(0);
    model.setParent(null);
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Tag);
    verifyModel((Tag) response.getEntity(), 0, Guid.Empty.toString());
}
Also used : Response(javax.ws.rs.core.Response) Tag(org.ovirt.engine.api.model.Tag) Tags(org.ovirt.engine.core.common.businessentities.Tags) Test(org.junit.Test)

Example 15 with Tags

use of org.ovirt.engine.core.common.businessentities.Tags in project ovirt-engine by oVirt.

the class AsyncDataProvider method fillTagsRecursive.

public void fillTagsRecursive(Tags tagToFill, List<Tags> children) {
    ArrayList<Tags> list = new ArrayList<>();
    for (Tags tag : children) {
        // tags child = new tags(tag.description, tag.parent_id, tag.IsReadonly, tag.tag_id, tag.tag_name);
        if (tag.getType() == TagsType.GeneralTag) {
            list.add(tag);
            if (tag.getChildren() != null) {
                fillTagsRecursive(tag, tag.getChildren());
            }
        }
    }
    tagToFill.setChildren(list);
}
Also used : ArrayList(java.util.ArrayList) Tags(org.ovirt.engine.core.common.businessentities.Tags)

Aggregations

Tags (org.ovirt.engine.core.common.businessentities.Tags)68 Test (org.junit.Test)34 ArrayList (java.util.ArrayList)8 Guid (org.ovirt.engine.core.compat.Guid)5 HashSet (java.util.HashSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Before (org.junit.Before)2 TagsTemplateMap (org.ovirt.engine.core.common.businessentities.TagsTemplateMap)2 TagsVdsMap (org.ovirt.engine.core.common.businessentities.TagsVdsMap)2 TagsVmMap (org.ovirt.engine.core.common.businessentities.TagsVmMap)2 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 List (java.util.List)1 PostConstruct (javax.annotation.PostConstruct)1 Named (javax.inject.Named)1 Singleton (javax.inject.Singleton)1 Response (javax.ws.rs.core.Response)1 Tag (org.ovirt.engine.api.model.Tag)1