Search in sources :

Example 1 with FactoryImpl

use of org.eclipse.che.api.factory.server.model.impl.FactoryImpl in project che by eclipse.

the class FactoryDaoTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    factories = new FactoryImpl[ENTRY_COUNT];
    users = new UserImpl[ENTRY_COUNT];
    for (int i = 0; i < ENTRY_COUNT; i++) {
        users[i] = new UserImpl("userId_" + i, "email_" + i, "name" + i);
    }
    for (int i = 0; i < ENTRY_COUNT; i++) {
        factories[i] = createFactory(i, users[i].getId());
    }
    userTckRepository.createAll(Arrays.asList(users));
    factoryTckRepository.createAll(Stream.of(factories).map(FactoryImpl::new).collect(toList()));
}
Also used : UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) FactoryImpl(org.eclipse.che.api.factory.server.model.impl.FactoryImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with FactoryImpl

use of org.eclipse.che.api.factory.server.model.impl.FactoryImpl in project che by eclipse.

the class FactoryDaoTest method shouldGetFactoryByIdAttribute.

@Test
public void shouldGetFactoryByIdAttribute() throws Exception {
    final FactoryImpl factory = factories[0];
    final List<Pair<String, String>> attributes = ImmutableList.of(Pair.of("id", factory.getId()));
    final List<FactoryImpl> result = factoryDao.getByAttribute(1, 0, attributes);
    assertEquals(new HashSet<>(result), ImmutableSet.of(factory));
}
Also used : FactoryImpl(org.eclipse.che.api.factory.server.model.impl.FactoryImpl) Pair(org.eclipse.che.commons.lang.Pair) Test(org.testng.annotations.Test)

Example 3 with FactoryImpl

use of org.eclipse.che.api.factory.server.model.impl.FactoryImpl in project che by eclipse.

the class FactoryManager method updateFactory.

/**
     * Updates factory and its images accordance to the new configuration.
     *
     * <p>Note: Updating uses replacement strategy,
     * therefore existing factory would be replaced with given update {@code update}
     *
     * @param update
     *         factory update
     * @return updated factory
     * @throws NullPointerException
     *         when {@code update} is null
     * @throws ConflictException
     *         when any conflict occurs (e.g Factory with given name already exists for {@code creator})
     * @throws NotFoundException
     *         when factory with given id not found
     * @throws ServerException
     *         when any server error occurs
     */
public Factory updateFactory(Factory update, Set<FactoryImage> images) throws ConflictException, NotFoundException, ServerException {
    requireNonNull(update);
    final AuthorImpl creator = factoryDao.getById(update.getId()).getCreator();
    return factoryDao.update(FactoryImpl.builder().from(new FactoryImpl(update, images)).setCreator(new AuthorImpl(creator.getUserId(), creator.getCreated())).build());
}
Also used : AuthorImpl(org.eclipse.che.api.factory.server.model.impl.AuthorImpl) FactoryImpl(org.eclipse.che.api.factory.server.model.impl.FactoryImpl)

Example 4 with FactoryImpl

use of org.eclipse.che.api.factory.server.model.impl.FactoryImpl in project che by eclipse.

the class FactoryDaoTest method shouldUpdateFactory.

// TODO fix after issue: https://github.com/eclipse/che/issues/2110
//    @Test(expectedExceptions = ConflictException.class)
//    public void shouldThrowConflictExceptionWhenCreatingFactoryWithExistingNameAndUserId() throws Exception {
//        final FactoryImpl factory = createFactory(10, users[0].getId());
//        final FactoryImpl existing = factories[0];
//        factory.getCreator().setUserId(existing.getCreator().getUserId());
//        factory.setName(existing.getName());
//        factoryDao.create(factory);
//    }
@Test
public void shouldUpdateFactory() throws Exception {
    final FactoryImpl update = factories[0];
    final String userId = update.getCreator().getUserId();
    update.setName("new-name");
    update.setV("5_0");
    final long currentTime = System.currentTimeMillis();
    update.setPolicies(new PoliciesImpl("ref", "match", "per-click", currentTime, currentTime + 1000));
    update.setCreator(new AuthorImpl(userId, currentTime));
    update.setButton(new ButtonImpl(new ButtonAttributesImpl("green", "icon", "opacity 0.9", true), Button.Type.NOLOGO));
    update.getIde().getOnAppClosed().getActions().add(new ActionImpl("remove file", ImmutableMap.of("file1", "/che/core/pom.xml")));
    update.getIde().getOnAppLoaded().getActions().add(new ActionImpl("edit file", ImmutableMap.of("file2", "/che/core/pom.xml")));
    update.getIde().getOnProjectsLoaded().getActions().add(new ActionImpl("open file", ImmutableMap.of("file2", "/che/pom.xml")));
    factoryDao.update(update);
    assertEquals(factoryDao.getById(update.getId()), update);
}
Also used : ActionImpl(org.eclipse.che.api.factory.server.model.impl.ActionImpl) ButtonImpl(org.eclipse.che.api.factory.server.model.impl.ButtonImpl) AuthorImpl(org.eclipse.che.api.factory.server.model.impl.AuthorImpl) PoliciesImpl(org.eclipse.che.api.factory.server.model.impl.PoliciesImpl) FactoryImpl(org.eclipse.che.api.factory.server.model.impl.FactoryImpl) ButtonAttributesImpl(org.eclipse.che.api.factory.server.model.impl.ButtonAttributesImpl) Test(org.testng.annotations.Test)

Example 5 with FactoryImpl

use of org.eclipse.che.api.factory.server.model.impl.FactoryImpl in project che by eclipse.

the class FactoryDaoTest method createFactory.

private static FactoryImpl createFactory(int index, String userId) {
    final long timeMs = System.currentTimeMillis();
    final ButtonImpl factoryButton = new ButtonImpl(new ButtonAttributesImpl("red", "logo", "style", true), Button.Type.LOGO);
    final AuthorImpl creator = new AuthorImpl(userId, timeMs);
    final PoliciesImpl policies = new PoliciesImpl("referrer", "match", "perClick", timeMs, timeMs + 1000);
    final Set<FactoryImage> images = new HashSet<>();
    final List<ActionImpl> a1 = new ArrayList<>(singletonList(new ActionImpl("id" + index, ImmutableMap.of("key1", "value1"))));
    final OnAppLoadedImpl onAppLoaded = new OnAppLoadedImpl(a1);
    final List<ActionImpl> a2 = new ArrayList<>(singletonList(new ActionImpl("id" + index, ImmutableMap.of("key2", "value2"))));
    final OnProjectsLoadedImpl onProjectsLoaded = new OnProjectsLoadedImpl(a2);
    final List<ActionImpl> a3 = new ArrayList<>(singletonList(new ActionImpl("id" + index, ImmutableMap.of("key3", "value3"))));
    final OnAppClosedImpl onAppClosed = new OnAppClosedImpl(a3);
    final IdeImpl ide = new IdeImpl(onAppLoaded, onProjectsLoaded, onAppClosed);
    final FactoryImpl factory = FactoryImpl.builder().generateId().setVersion("4_0").setName("factoryName" + index).setButton(factoryButton).setCreator(creator).setPolicies(policies).setImages(images).setIde(ide).build();
    factory.setWorkspace(createWorkspaceConfig(index));
    return factory;
}
Also used : OnAppLoadedImpl(org.eclipse.che.api.factory.server.model.impl.OnAppLoadedImpl) OnProjectsLoadedImpl(org.eclipse.che.api.factory.server.model.impl.OnProjectsLoadedImpl) ArrayList(java.util.ArrayList) FactoryImpl(org.eclipse.che.api.factory.server.model.impl.FactoryImpl) FactoryImage(org.eclipse.che.api.factory.server.FactoryImage) IdeImpl(org.eclipse.che.api.factory.server.model.impl.IdeImpl) ActionImpl(org.eclipse.che.api.factory.server.model.impl.ActionImpl) ButtonImpl(org.eclipse.che.api.factory.server.model.impl.ButtonImpl) AuthorImpl(org.eclipse.che.api.factory.server.model.impl.AuthorImpl) PoliciesImpl(org.eclipse.che.api.factory.server.model.impl.PoliciesImpl) ButtonAttributesImpl(org.eclipse.che.api.factory.server.model.impl.ButtonAttributesImpl) HashSet(java.util.HashSet) OnAppClosedImpl(org.eclipse.che.api.factory.server.model.impl.OnAppClosedImpl)

Aggregations

FactoryImpl (org.eclipse.che.api.factory.server.model.impl.FactoryImpl)13 Test (org.testng.annotations.Test)6 Transactional (com.google.inject.persist.Transactional)3 AuthorImpl (org.eclipse.che.api.factory.server.model.impl.AuthorImpl)3 EntityManager (javax.persistence.EntityManager)2 ActionImpl (org.eclipse.che.api.factory.server.model.impl.ActionImpl)2 ButtonAttributesImpl (org.eclipse.che.api.factory.server.model.impl.ButtonAttributesImpl)2 ButtonImpl (org.eclipse.che.api.factory.server.model.impl.ButtonImpl)2 PoliciesImpl (org.eclipse.che.api.factory.server.model.impl.PoliciesImpl)2 Pair (org.eclipse.che.commons.lang.Pair)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 StringJoiner (java.util.StringJoiner)1 NotFoundException (org.eclipse.che.api.core.NotFoundException)1 ServerException (org.eclipse.che.api.core.ServerException)1 FactoryImage (org.eclipse.che.api.factory.server.FactoryImage)1 IdeImpl (org.eclipse.che.api.factory.server.model.impl.IdeImpl)1 OnAppClosedImpl (org.eclipse.che.api.factory.server.model.impl.OnAppClosedImpl)1