Rework mechanism to TckListener instead of TckModuleFactory (#2953)
It solves two problems: - we initialize test instances with new injectors instead of using default child injector mechanism. It resolves issues with injection of injector in GuiceEntityListenerInjectionManager. - we add ability to clean resources after tck test finish. So it allow close entity manager after after tck tests with jpa and resolve problems with reusing static fields by eclipse link by EntityManagerFactory when different tests in one module use it6.19.x
parent
4930dd6471
commit
787041dd4e
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012-2016 Codenvy, S.A.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Codenvy, S.A. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.che.commons.test.tck;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
|
||||
/**
|
||||
* This class is designed to close {@link EntityManagerFactory}
|
||||
* on finish of tck test with jpa implementation.
|
||||
*
|
||||
* <p/>
|
||||
* Examples of usage:<br>
|
||||
* <code>bind(TckResourcesCleaner.class).to(JpaCleaner.class)</code><br>
|
||||
* <code>bind(TckResourcesCleaner.class).annotatedWith(Names.named(MyTckTest.class.getName())).to(JpaCleaner.class);</code>
|
||||
*
|
||||
* @author Sergii Leschenko
|
||||
*/
|
||||
public class JpaCleaner implements TckResourcesCleaner {
|
||||
@Inject
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
@Override
|
||||
public void clean() {
|
||||
entityManagerFactory.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -11,23 +11,35 @@
|
|||
package org.eclipse.che.commons.test.tck;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.ConfigurationException;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.name.Names;
|
||||
|
||||
import org.testng.IModuleFactory;
|
||||
import org.testng.ITestContext;
|
||||
import org.testng.ITestNGMethod;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
/**
|
||||
* The factory is designed to instantiate {@link TckModule tck modules}
|
||||
* using {@link ServiceLoader} mechanism. The components
|
||||
* provided by those modules will be injected into a test class
|
||||
* whether it's necessary to do so.
|
||||
* The listener is designed to instantiate {@link TckModule tck modules}
|
||||
* using {@link ServiceLoader} mechanism. The components provided by those
|
||||
* modules will be injected into a test class whether it's necessary to do so.
|
||||
* For each test class will be used new instance of injector.
|
||||
* Listener requires tck test to be in own separated suite, if it finds more tests
|
||||
* in suite it'll throw {@link IllegalArgumentException} on suite start.
|
||||
* After test suite is finished listener'll try to find test specific or common
|
||||
* instance of {@link TckResourcesCleaner}. It is optional and can be bound in modules.
|
||||
*
|
||||
* <p>The factory expects at least one implementation of {@code TckModule}
|
||||
* <p>The listener expects at least one implementation of {@code TckModule}
|
||||
* to be configured, if it doesn't find any of the {@code TckModule}
|
||||
* implementations then it will report an appropriate exception
|
||||
* and TckTest will fail(as it requires components to be injected into it).
|
||||
|
|
@ -38,9 +50,8 @@ import static java.lang.String.format;
|
|||
* <pre>
|
||||
* package org.eclipse.mycomponent;
|
||||
*
|
||||
* @org.testng.annotations.Guice(moduleFactory = TckModuleFactory.class)
|
||||
* // Good practice to define suiteName for TCK tests as it makes easier
|
||||
* // to implement logic related to certain tests in ITestNGListener implementations
|
||||
* @org.testng.annotations.Listeners(TckListener)
|
||||
* // Tck test must have own suite because of cleaning resources on suite finishing
|
||||
* @org.testng.annotations.Test(suiteName = "MySuite")
|
||||
* class SubjectTest {
|
||||
*
|
||||
|
|
@ -59,6 +70,8 @@ import static java.lang.String.format;
|
|||
* public void configure() {
|
||||
* bind(Component1.class).to(...);
|
||||
* bind(Component2.class).toInstance(new Component2(() -> testContext.getAttribute("server_url").toString()));
|
||||
* bind(TckResourcesCleaner.class).to(...);
|
||||
* bind(TckResourcesCleaner.class).annotatedWith(Names.named(SubjectTest.class.getName())).to(...);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
|
|
@ -87,22 +100,69 @@ import static java.lang.String.format;
|
|||
* </pre>
|
||||
*
|
||||
* @author Yevhenii Voevodin
|
||||
* @see org.testng.annotations.Guice
|
||||
* @see IModuleFactory
|
||||
* @author Sergii Leschenko
|
||||
* @see org.testng.annotations.Listeners
|
||||
* @see org.testng.IInvokedMethodListener
|
||||
* @see TckResourcesCleaner
|
||||
*/
|
||||
public class TckModuleFactory implements IModuleFactory {
|
||||
public class TckListener extends AbstractTestListener {
|
||||
private Injector injector;
|
||||
private Object instance;
|
||||
|
||||
@Override
|
||||
public Module createModule(ITestContext context, Class<?> testClass) {
|
||||
public void onStart(ITestContext context) {
|
||||
final Set<Object> instances = Stream.of(context.getAllTestMethods())
|
||||
.map(ITestNGMethod::getInstance)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
if (instances.size() != 1) {
|
||||
throw new IllegalStateException("Tck test should be one and only one in suite.");
|
||||
}
|
||||
|
||||
instance = instances.iterator().next();
|
||||
|
||||
injector = Guice.createInjector(createModule(context, instance.getClass().getName()));
|
||||
injector.injectMembers(instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish(ITestContext context) {
|
||||
if (injector == null || instance == null) {
|
||||
throw new IllegalStateException("Looks like onFinish method is invoked before onStart.");
|
||||
}
|
||||
|
||||
// try to get test specific resources cleaner
|
||||
TckResourcesCleaner resourcesCleaner = getResourcesCleaner(injector,
|
||||
Key.get(TckResourcesCleaner.class,
|
||||
Names.named(instance.getClass().getName())));
|
||||
if (resourcesCleaner == null) {
|
||||
// try to get common resources cleaner
|
||||
resourcesCleaner = getResourcesCleaner(injector, Key.get(TckResourcesCleaner.class));
|
||||
}
|
||||
|
||||
if (resourcesCleaner != null) {
|
||||
resourcesCleaner.clean();
|
||||
}
|
||||
}
|
||||
|
||||
private TckResourcesCleaner getResourcesCleaner(Injector injector, Key<TckResourcesCleaner> key) {
|
||||
try {
|
||||
return injector.getInstance(key);
|
||||
} catch (ConfigurationException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Module createModule(ITestContext testContext, String name) {
|
||||
final Iterator<TckModule> moduleIterator = ServiceLoader.load(TckModule.class).iterator();
|
||||
if (!moduleIterator.hasNext()) {
|
||||
throw new IllegalStateException(format("Couldn't find a TckModule configuration. " +
|
||||
"You probably forgot to configure resources/META-INF/services/%s, or even " +
|
||||
"provide an implementation of the TckModule which is required by the tck test class %s",
|
||||
TckModule.class.getName(),
|
||||
testClass.getName()));
|
||||
name));
|
||||
}
|
||||
return new CompoundModule(context, moduleIterator);
|
||||
return new CompoundModule(testContext, moduleIterator);
|
||||
}
|
||||
|
||||
private static class CompoundModule extends AbstractModule {
|
||||
|
|
@ -13,7 +13,6 @@ package org.eclipse.che.commons.test.tck;
|
|||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
|
||||
import org.testng.IModuleFactory;
|
||||
import org.testng.ITestContext;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
|
|
@ -26,20 +25,18 @@ import java.util.ServiceLoader;
|
|||
* and for injecting them later. So each module which is TCK module must
|
||||
* provide the implementations list(as described by {@code ServiceLoader} mechanism)
|
||||
* in the file named <i>org.eclipse.che.commons.test.tck.TckModule</i> usually under
|
||||
* <i>test/resources/META-INF/services</i> directory, then the {@link TckModuleFactory}
|
||||
* <i>test/resources/META-INF/services</i> directory, then the {@link TckListener}
|
||||
* will recognise and load it.
|
||||
*
|
||||
* @author Yevhenii Voevodin
|
||||
* @see TckModuleFactory
|
||||
* @see TckListener
|
||||
*/
|
||||
public abstract class TckModule extends AbstractModule {
|
||||
|
||||
/**
|
||||
* It is guaranteed that this field is always present and
|
||||
* can be reused by implementation, the value is equal to the
|
||||
* {@link IModuleFactory#createModule(ITestContext, Class)} first
|
||||
* parameter and will be set by {@link TckModuleFactory} immediately after module
|
||||
* implementation is loaded by {@link ServiceLoader}.
|
||||
* can be reused by implementation, it will be set by {@link TckListener} immediately
|
||||
* after module implementation is loaded by {@link ServiceLoader}.
|
||||
*/
|
||||
private ITestContext testContext;
|
||||
|
||||
|
|
@ -50,7 +47,7 @@ public abstract class TckModule extends AbstractModule {
|
|||
|
||||
/**
|
||||
* Sets the context of currently executing test suite.
|
||||
* This method designed to be used by {@link TckModuleFactory} for setting
|
||||
* This method designed to be used by {@link TckListener} for setting
|
||||
* the context before installing modules.
|
||||
*/
|
||||
void setTestContext(ITestContext testContext) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012-2016 Codenvy, S.A.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Codenvy, S.A. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.che.commons.test.tck;
|
||||
|
||||
/**
|
||||
* This class is designed to clean up resources after tck test.
|
||||
*
|
||||
* <p>Implementation should be defined in {@link TckModule}.
|
||||
* It can be defined common for all tests or test specific by using @Named annotation.
|
||||
* Cleaning of resources is invoked after finish of all tests methods from one test suite
|
||||
* that should contains one and only one tck test class.
|
||||
*
|
||||
* <p>The usage example:
|
||||
* <pre>
|
||||
* class MyTckModule extends TckModule {
|
||||
* public void configure() {
|
||||
* bind(TckResourcesCleaner.class).to(...);
|
||||
* bind(TckResourcesCleaner.class).annotatedWith(Names.named(SomeTest.class.getName())).to(...);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @author Sergii Leschenko
|
||||
* @see TckListener
|
||||
*/
|
||||
public interface TckResourcesCleaner {
|
||||
/**
|
||||
* Clean up resources.
|
||||
*
|
||||
* <p>Note: it is invoked after finish of all methods from one test suite.
|
||||
*/
|
||||
void clean();
|
||||
}
|
||||
|
|
@ -11,8 +11,6 @@
|
|||
package org.eclipse.che.commons.test.tck;
|
||||
|
||||
import org.testng.ITestContext;
|
||||
import org.testng.ITestListener;
|
||||
import org.testng.ITestResult;
|
||||
|
||||
/**
|
||||
* Listener representing fake db server url injection for testing "attributes sharing"
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
package org.eclipse.che.commons.test.tck;
|
||||
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Listeners;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -24,7 +24,7 @@ import static org.testng.Assert.assertNotNull;
|
|||
*
|
||||
* @author Yevhenii Voevodin
|
||||
*/
|
||||
@Guice(moduleFactory = TckModuleFactory.class)
|
||||
@Listeners(TckListener.class)
|
||||
public class TckComponentsTest {
|
||||
|
||||
@Inject
|
||||
|
|
|
|||
|
|
@ -14,12 +14,12 @@ import org.eclipse.che.account.spi.AccountDao;
|
|||
import org.eclipse.che.account.spi.AccountImpl;
|
||||
import org.eclipse.che.api.core.NotFoundException;
|
||||
import org.eclipse.che.commons.lang.NameGenerator;
|
||||
import org.eclipse.che.commons.test.tck.TckModuleFactory;
|
||||
import org.eclipse.che.commons.test.tck.TckListener;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepositoryException;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Listeners;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -32,7 +32,7 @@ import static org.testng.Assert.assertEquals;
|
|||
*
|
||||
* @author Sergii Leschenko
|
||||
*/
|
||||
@Guice(moduleFactory = TckModuleFactory.class)
|
||||
@Listeners(TckListener.class)
|
||||
@Test(suiteName = AccountDaoTest.SUITE_NAME)
|
||||
public class AccountDaoTest {
|
||||
public static final String SUITE_NAME = "AccountDaoTck";
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@ import org.eclipse.che.account.spi.AccountImpl;
|
|||
import org.eclipse.che.account.spi.jpa.JpaAccountDao;
|
||||
import org.eclipse.che.api.core.jdbc.jpa.eclipselink.EntityListenerInjectionManagerInitializer;
|
||||
import org.eclipse.che.api.core.jdbc.jpa.guice.JpaInitializer;
|
||||
import org.eclipse.che.commons.test.tck.JpaCleaner;
|
||||
import org.eclipse.che.commons.test.tck.TckModule;
|
||||
import org.eclipse.che.commons.test.tck.TckResourcesCleaner;
|
||||
import org.eclipse.che.commons.test.tck.repository.JpaTckRepository;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
|
||||
|
|
@ -31,6 +33,8 @@ public class AccountJpaTckModule extends TckModule {
|
|||
install(new JpaPersistModule("main"));
|
||||
bind(JpaInitializer.class).asEagerSingleton();
|
||||
bind(EntityListenerInjectionManagerInitializer.class).asEagerSingleton();
|
||||
bind(TckResourcesCleaner.class).to(JpaCleaner.class);
|
||||
|
||||
bind(new TypeLiteral<TckRepository<AccountImpl>>() {}).toInstance(new JpaTckRepository<>(AccountImpl.class));
|
||||
|
||||
bind(AccountDao.class).to(JpaAccountDao.class);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ import org.eclipse.che.api.user.server.model.impl.ProfileImpl;
|
|||
import org.eclipse.che.api.user.server.model.impl.UserImpl;
|
||||
import org.eclipse.che.api.user.server.spi.ProfileDao;
|
||||
import org.eclipse.che.api.user.server.spi.UserDao;
|
||||
import org.eclipse.che.commons.test.tck.JpaCleaner;
|
||||
import org.eclipse.che.commons.test.tck.TckModule;
|
||||
import org.eclipse.che.commons.test.tck.TckResourcesCleaner;
|
||||
import org.eclipse.che.commons.test.tck.repository.JpaTckRepository;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
import org.eclipse.che.security.PasswordEncryptor;
|
||||
|
|
@ -40,6 +42,7 @@ public class JpaTckModule extends TckModule {
|
|||
install(new JpaPersistModule("main"));
|
||||
bind(JpaInitializer.class).asEagerSingleton();
|
||||
bind(EntityListenerInjectionManagerInitializer.class).asEagerSingleton();
|
||||
bind(TckResourcesCleaner.class).to(JpaCleaner.class);
|
||||
|
||||
bind(new TypeLiteral<TckRepository<UserImpl>>() {}).toInstance(new JpaTckRepository<>(UserImpl.class));
|
||||
bind(new TypeLiteral<TckRepository<FactoryImpl>>() {}).toInstance(new JpaTckRepository<>(FactoryImpl.class));
|
||||
|
|
@ -51,5 +54,6 @@ public class JpaTckModule extends TckModule {
|
|||
bind(FactoryDao.class).to(JpaFactoryDao.class);
|
||||
|
||||
bind(PasswordEncryptor.class).to(SHA512PasswordEncryptor.class).in(Singleton.class);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,11 +39,11 @@ import org.eclipse.che.api.workspace.server.model.impl.ServerConf2Impl;
|
|||
import org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl;
|
||||
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl;
|
||||
import org.eclipse.che.commons.lang.Pair;
|
||||
import org.eclipse.che.commons.test.tck.TckModuleFactory;
|
||||
import org.eclipse.che.commons.test.tck.TckListener;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Listeners;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -65,7 +65,7 @@ import static org.testng.Assert.assertEquals;
|
|||
*
|
||||
* @author Anton Korneta
|
||||
*/
|
||||
@Guice(moduleFactory = TckModuleFactory.class)
|
||||
@Listeners(TckListener.class)
|
||||
@Test(suiteName = FactoryDaoTest.SUITE_NAME)
|
||||
public class FactoryDaoTest {
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@ import org.eclipse.che.api.machine.server.model.impl.SnapshotImpl;
|
|||
import org.eclipse.che.api.machine.server.recipe.RecipeImpl;
|
||||
import org.eclipse.che.api.machine.server.spi.RecipeDao;
|
||||
import org.eclipse.che.api.machine.server.spi.SnapshotDao;
|
||||
import org.eclipse.che.commons.test.tck.JpaCleaner;
|
||||
import org.eclipse.che.commons.test.tck.TckModule;
|
||||
import org.eclipse.che.commons.test.tck.TckResourcesCleaner;
|
||||
import org.eclipse.che.commons.test.tck.repository.JpaTckRepository;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
|
||||
|
|
@ -32,7 +34,7 @@ public class JpaTckModule extends TckModule {
|
|||
protected void configure() {
|
||||
install(new JpaPersistModule("main"));
|
||||
bind(JpaInitializer.class).asEagerSingleton();
|
||||
|
||||
bind(TckResourcesCleaner.class).to(JpaCleaner.class);
|
||||
bind(EntityListenerInjectionManagerInitializer.class).asEagerSingleton();
|
||||
|
||||
bind(new TypeLiteral<TckRepository<RecipeImpl>>() {}).toInstance(new JpaTckRepository<>(RecipeImpl.class));
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ import org.eclipse.che.api.core.NotFoundException;
|
|||
import org.eclipse.che.api.machine.server.recipe.RecipeImpl;
|
||||
import org.eclipse.che.api.machine.server.spi.RecipeDao;
|
||||
import org.eclipse.che.commons.lang.NameGenerator;
|
||||
import org.eclipse.che.commons.test.tck.TckModuleFactory;
|
||||
import org.eclipse.che.commons.test.tck.TckListener;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Listeners;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -31,7 +31,6 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
|
|
@ -40,7 +39,7 @@ import static org.testng.Assert.assertTrue;
|
|||
*
|
||||
* @author Anton Korneta
|
||||
*/
|
||||
@Guice(moduleFactory = TckModuleFactory.class)
|
||||
@Listeners(TckListener.class)
|
||||
@Test(suiteName = RecipeDaoTest.SUITE_NAME)
|
||||
public class RecipeDaoTest {
|
||||
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@ import org.eclipse.che.api.machine.server.exception.SnapshotException;
|
|||
import org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl;
|
||||
import org.eclipse.che.api.machine.server.model.impl.SnapshotImpl;
|
||||
import org.eclipse.che.api.machine.server.spi.SnapshotDao;
|
||||
import org.eclipse.che.commons.test.tck.TckModuleFactory;
|
||||
import org.eclipse.che.commons.test.tck.TckListener;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepositoryException;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Listeners;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
|
@ -40,7 +40,7 @@ import static org.testng.Assert.fail;
|
|||
*
|
||||
* @author Yevhenii Voevodin
|
||||
*/
|
||||
@Guice(moduleFactory = TckModuleFactory.class)
|
||||
@Listeners(TckListener.class)
|
||||
@Test(suiteName = SnapshotDaoTest.SUITE_NAME)
|
||||
public class SnapshotDaoTest {
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@ import org.eclipse.che.api.core.jdbc.jpa.guice.JpaInitializer;
|
|||
import org.eclipse.che.api.ssh.server.model.impl.SshPairImpl;
|
||||
import org.eclipse.che.api.ssh.server.spi.SshDao;
|
||||
import org.eclipse.che.api.user.server.model.impl.UserImpl;
|
||||
import org.eclipse.che.commons.test.tck.JpaCleaner;
|
||||
import org.eclipse.che.commons.test.tck.TckModule;
|
||||
import org.eclipse.che.commons.test.tck.TckResourcesCleaner;
|
||||
import org.eclipse.che.commons.test.tck.repository.JpaTckRepository;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
|
||||
|
|
@ -37,5 +39,6 @@ public class SshTckModule extends TckModule {
|
|||
bind(JpaInitializer.class).asEagerSingleton();
|
||||
bind(EntityListenerInjectionManagerInitializer.class).asEagerSingleton();
|
||||
bind(org.eclipse.che.api.core.h2.jdbc.jpa.eclipselink.H2ExceptionHandler.class);
|
||||
bind(TckResourcesCleaner.class).to(JpaCleaner.class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@ import org.eclipse.che.api.ssh.server.model.impl.SshPairImpl;
|
|||
import org.eclipse.che.api.ssh.server.spi.SshDao;
|
||||
import org.eclipse.che.api.user.server.model.impl.UserImpl;
|
||||
import org.eclipse.che.commons.lang.NameGenerator;
|
||||
import org.eclipse.che.commons.test.tck.TckModuleFactory;
|
||||
import org.eclipse.che.commons.test.tck.TckListener;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepositoryException;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Listeners;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -41,10 +41,11 @@ import static org.testng.Assert.fail;
|
|||
* @author Mihail Kuznyetsov.
|
||||
* @author Yevhenii Voevodin
|
||||
*/
|
||||
@Guice(moduleFactory = TckModuleFactory.class)
|
||||
@Listeners(TckListener.class)
|
||||
@Test(suiteName = SshDaoTest.SUITE_NAME)
|
||||
public class SshDaoTest {
|
||||
public static final String SUITE_NAME = "SshDaoTck";
|
||||
public static final String SUITE_NAME = "SshDaoTck";
|
||||
|
||||
private static final int COUNT_OF_PAIRS = 6;
|
||||
private static final int COUNT_OF_USERS = 3;
|
||||
|
||||
|
|
@ -73,8 +74,8 @@ public class SshDaoTest {
|
|||
pairs = new SshPairImpl[COUNT_OF_PAIRS];
|
||||
|
||||
for (int i = 0; i < COUNT_OF_PAIRS; i++) {
|
||||
pairs[i] = new SshPairImpl("owner" + i/3, // 3 each pairs share the same owner
|
||||
"service" + i/2, // each 2 pairs share the same service
|
||||
pairs[i] = new SshPairImpl("owner" + i / 3, // 3 each pairs share the same owner
|
||||
"service" + i / 2, // each 2 pairs share the same service
|
||||
"name" + i,
|
||||
NameGenerator.generate("publicKey-", 20),
|
||||
NameGenerator.generate("privateKey-", 20));
|
||||
|
|
@ -107,8 +108,9 @@ public class SshDaoTest {
|
|||
public void shouldThrowNpeOnCreateIfSshPairIsNull() throws Exception {
|
||||
sshDao.create(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetSshPairByNameOwnerAndService() throws Exception{
|
||||
public void shouldGetSshPairByNameOwnerAndService() throws Exception {
|
||||
SshPairImpl sshPair = pairs[0];
|
||||
|
||||
sshDao.get(sshPair.getOwner(), sshPair.getService(), sshPair.getName());
|
||||
|
|
@ -122,22 +124,22 @@ public class SshDaoTest {
|
|||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void shouldThrowNpeOnGetSshPairWhenOwnerIsNull() throws Exception{
|
||||
public void shouldThrowNpeOnGetSshPairWhenOwnerIsNull() throws Exception {
|
||||
sshDao.get(null, "service", "name");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void shouldThrowNpeOnGetSshPairWhenServiceIsNull() throws Exception{
|
||||
public void shouldThrowNpeOnGetSshPairWhenServiceIsNull() throws Exception {
|
||||
sshDao.get("owner", null, "name");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void shouldThrowNpeOnGetSshPairWhenNameIsNull() throws Exception{
|
||||
public void shouldThrowNpeOnGetSshPairWhenNameIsNull() throws Exception {
|
||||
sshDao.get("owner", "service", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetSshPairListByNameAndService() throws Exception{
|
||||
public void shouldGetSshPairListByNameAndService() throws Exception {
|
||||
SshPairImpl sshPair1 = pairs[0];
|
||||
SshPairImpl sshPair2 = pairs[1];
|
||||
assertEquals(sshPair1.getOwner(), sshPair2.getOwner(), "Owner must be the same");
|
||||
|
|
@ -153,12 +155,12 @@ public class SshDaoTest {
|
|||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void shouldThrowNpeOnGetSshPairsListWhenOwnerIsNull() throws Exception{
|
||||
public void shouldThrowNpeOnGetSshPairsListWhenOwnerIsNull() throws Exception {
|
||||
sshDao.get(null, "service");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void shouldThrowNpeOnGetSshPairsListWhenServiceIsNull() throws Exception{
|
||||
public void shouldThrowNpeOnGetSshPairsListWhenServiceIsNull() throws Exception {
|
||||
sshDao.get("owner", null);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,10 +72,6 @@
|
|||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-commons-lang</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-commons-test</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
|
|
@ -120,6 +116,11 @@
|
|||
<artifactId>che-core-commons-json</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.che.core</groupId>
|
||||
<artifactId>che-core-commons-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.persistence</groupId>
|
||||
<artifactId>eclipselink</artifactId>
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ package org.eclipse.che.api.user.server.jpa;
|
|||
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.name.Names;
|
||||
import com.google.inject.persist.jpa.JpaPersistModule;
|
||||
|
||||
import org.eclipse.che.api.core.jdbc.jpa.eclipselink.EntityListenerInjectionManagerInitializer;
|
||||
|
|
@ -21,13 +22,19 @@ import org.eclipse.che.api.user.server.model.impl.UserImpl;
|
|||
import org.eclipse.che.api.user.server.spi.PreferenceDao;
|
||||
import org.eclipse.che.api.user.server.spi.ProfileDao;
|
||||
import org.eclipse.che.api.user.server.spi.UserDao;
|
||||
import org.eclipse.che.api.user.server.spi.tck.PreferenceDaoTest;
|
||||
import org.eclipse.che.api.user.server.spi.tck.ProfileDaoTest;
|
||||
import org.eclipse.che.api.user.server.spi.tck.UserDaoTest;
|
||||
import org.eclipse.che.commons.lang.Pair;
|
||||
import org.eclipse.che.commons.test.tck.JpaCleaner;
|
||||
import org.eclipse.che.commons.test.tck.TckModule;
|
||||
import org.eclipse.che.commons.test.tck.TckResourcesCleaner;
|
||||
import org.eclipse.che.commons.test.tck.repository.JpaTckRepository;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
import org.eclipse.che.security.PasswordEncryptor;
|
||||
import org.eclipse.che.security.SHA512PasswordEncryptor;
|
||||
|
||||
import javax.inject.Named;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -40,6 +47,7 @@ public class JpaTckModule extends TckModule {
|
|||
install(new JpaPersistModule("main"));
|
||||
bind(JpaInitializer.class).asEagerSingleton();
|
||||
bind(EntityListenerInjectionManagerInitializer.class).asEagerSingleton();
|
||||
bind(TckResourcesCleaner.class).to(JpaCleaner.class);
|
||||
|
||||
bind(new TypeLiteral<TckRepository<UserImpl>>() {}).to(UserJpaTckRepository.class);
|
||||
bind(new TypeLiteral<TckRepository<ProfileImpl>>() {}).toInstance(new JpaTckRepository<>(ProfileImpl.class));
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ public class DataObjectsTest {
|
|||
assertFalse(copy.getAttributes().containsKey("new-attribute"));
|
||||
}
|
||||
|
||||
@Test(dataProvider = "singleObjectProvider")
|
||||
@Test(dataProvider = "reflexivenessProvider")
|
||||
@SuppressWarnings("all")
|
||||
public void testReflexiveness(Object obj) throws Exception {
|
||||
assertTrue(obj.equals(obj));
|
||||
|
|
@ -148,7 +148,7 @@ public class DataObjectsTest {
|
|||
assertTrue(object1.equals(object2));
|
||||
}
|
||||
|
||||
@Test(dataProvider = "singleObjectProvider")
|
||||
@Test(dataProvider = "reflexivenessProvider")
|
||||
@SuppressWarnings("all")
|
||||
public void testNotEqualityToNull(Object object) throws Exception {
|
||||
assertFalse(object.equals(null));
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ import com.google.common.collect.ImmutableMap;
|
|||
import org.eclipse.che.api.user.server.model.impl.UserImpl;
|
||||
import org.eclipse.che.api.user.server.spi.PreferenceDao;
|
||||
import org.eclipse.che.commons.lang.Pair;
|
||||
import org.eclipse.che.commons.test.tck.TckModuleFactory;
|
||||
import org.eclipse.che.commons.test.tck.TckListener;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Listeners;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -39,7 +39,7 @@ import static org.testng.Assert.assertTrue;
|
|||
*
|
||||
* @author Anton Korneta
|
||||
*/
|
||||
@Guice(moduleFactory = TckModuleFactory.class)
|
||||
@Listeners(TckListener.class)
|
||||
@Test(suiteName = PreferenceDaoTest.SUITE_NAME)
|
||||
public class PreferenceDaoTest {
|
||||
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@ import org.eclipse.che.api.user.server.model.impl.ProfileImpl;
|
|||
import org.eclipse.che.api.user.server.model.impl.UserImpl;
|
||||
import org.eclipse.che.api.user.server.spi.ProfileDao;
|
||||
import org.eclipse.che.commons.lang.NameGenerator;
|
||||
import org.eclipse.che.commons.test.tck.TckModuleFactory;
|
||||
import org.eclipse.che.commons.test.tck.TckListener;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepositoryException;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Listeners;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -40,7 +40,7 @@ import static org.testng.Assert.assertEquals;
|
|||
*
|
||||
* @author Yevhenii Voevodin
|
||||
*/
|
||||
@Guice(moduleFactory = TckModuleFactory.class)
|
||||
@Listeners(TckListener.class)
|
||||
@Test(suiteName = ProfileDaoTest.SUITE_NAME)
|
||||
public class ProfileDaoTest {
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ public class ProfileDaoTest {
|
|||
@Inject
|
||||
private TckRepository<ProfileImpl> profileTckRepository;
|
||||
@Inject
|
||||
private TckRepository<UserImpl> userTckRepository;
|
||||
private TckRepository<UserImpl> userTckRepository;
|
||||
|
||||
@BeforeMethod
|
||||
private void setUp() throws TckRepositoryException {
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@ import org.eclipse.che.api.user.server.Constants;
|
|||
import org.eclipse.che.api.user.server.model.impl.UserImpl;
|
||||
import org.eclipse.che.api.user.server.spi.UserDao;
|
||||
import org.eclipse.che.commons.lang.NameGenerator;
|
||||
import org.eclipse.che.commons.test.tck.TckModuleFactory;
|
||||
import org.eclipse.che.commons.test.tck.TckListener;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepositoryException;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Listeners;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -42,7 +42,7 @@ import static org.testng.AssertJUnit.assertTrue;
|
|||
*
|
||||
* @author Yevhenii Voevodin
|
||||
*/
|
||||
@Guice(moduleFactory = TckModuleFactory.class)
|
||||
@Listeners(TckListener.class)
|
||||
@Test(suiteName = UserDaoTest.SUITE_NAME)
|
||||
public class UserDaoTest {
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@ import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl;
|
|||
import org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl;
|
||||
import org.eclipse.che.api.workspace.server.spi.StackDao;
|
||||
import org.eclipse.che.api.workspace.server.spi.WorkspaceDao;
|
||||
import org.eclipse.che.commons.test.tck.JpaCleaner;
|
||||
import org.eclipse.che.commons.test.tck.TckModule;
|
||||
import org.eclipse.che.commons.test.tck.TckResourcesCleaner;
|
||||
import org.eclipse.che.commons.test.tck.repository.JpaTckRepository;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
|
||||
|
|
@ -35,6 +37,7 @@ public class WorkspaceTckModule extends TckModule {
|
|||
bind(JpaInitializer.class).asEagerSingleton();
|
||||
bind(EntityListenerInjectionManagerInitializer.class).asEagerSingleton();
|
||||
bind(org.eclipse.che.api.core.h2.jdbc.jpa.eclipselink.H2ExceptionHandler.class);
|
||||
bind(TckResourcesCleaner.class).to(JpaCleaner.class);
|
||||
|
||||
bind(new TypeLiteral<TckRepository<AccountImpl>>() {}).toInstance(new JpaTckRepository<>(AccountImpl.class));
|
||||
bind(new TypeLiteral<TckRepository<WorkspaceImpl>>() {}).toInstance(new JpaTckRepository<>(WorkspaceImpl.class));
|
||||
|
|
|
|||
|
|
@ -24,12 +24,12 @@ import org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl;
|
|||
import org.eclipse.che.api.workspace.server.model.impl.stack.StackSourceImpl;
|
||||
import org.eclipse.che.api.workspace.server.spi.StackDao;
|
||||
import org.eclipse.che.api.workspace.server.stack.image.StackIcon;
|
||||
import org.eclipse.che.commons.test.tck.TckModuleFactory;
|
||||
import org.eclipse.che.commons.test.tck.TckListener;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepositoryException;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Listeners;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
|
@ -46,7 +46,7 @@ import static org.testng.Assert.assertTrue;
|
|||
*
|
||||
* @author Yevhenii Voevodin
|
||||
*/
|
||||
@Guice(moduleFactory = TckModuleFactory.class)
|
||||
@Listeners(TckListener.class)
|
||||
@Test(suiteName = StackDaoTest.SUITE_NAME)
|
||||
public class StackDaoTest {
|
||||
|
||||
|
|
@ -228,7 +228,7 @@ public class StackDaoTest {
|
|||
|
||||
@Test
|
||||
public void shouldPublishStackPersistedEventAfterStackIsPersisted() throws Exception {
|
||||
final boolean[] isNotified = new boolean[] { false };
|
||||
final boolean[] isNotified = new boolean[] {false};
|
||||
eventService.subscribe(event -> isNotified[0] = true, StackPersistedEvent.class);
|
||||
|
||||
stackDao.create(createStack("test", "test"));
|
||||
|
|
@ -244,19 +244,19 @@ public class StackDaoTest {
|
|||
|
||||
private static StackImpl createStack(String id, String name) {
|
||||
final StackImpl stack = StackImpl.builder()
|
||||
.setId(id)
|
||||
.setName(name)
|
||||
.setCreator("user123")
|
||||
.setDescription(id + "-description")
|
||||
.setScope(id + "-scope")
|
||||
.setTags(asList(id + "-tag1", id + "-tag2"))
|
||||
.setComponents(asList(new StackComponentImpl(id + "-component1", id + "-component1-version"),
|
||||
new StackComponentImpl(id + "-component2", id + "-component2-version")))
|
||||
.setSource(new StackSourceImpl(id + "-type", id + "-origin"))
|
||||
.setStackIcon(new StackIcon(id + "-icon",
|
||||
id + "-media-type",
|
||||
"0x1234567890abcdef".getBytes()))
|
||||
.build();
|
||||
.setId(id)
|
||||
.setName(name)
|
||||
.setCreator("user123")
|
||||
.setDescription(id + "-description")
|
||||
.setScope(id + "-scope")
|
||||
.setTags(asList(id + "-tag1", id + "-tag2"))
|
||||
.setComponents(asList(new StackComponentImpl(id + "-component1", id + "-component1-version"),
|
||||
new StackComponentImpl(id + "-component2", id + "-component2-version")))
|
||||
.setSource(new StackSourceImpl(id + "-type", id + "-origin"))
|
||||
.setStackIcon(new StackIcon(id + "-icon",
|
||||
id + "-media-type",
|
||||
"0x1234567890abcdef".getBytes()))
|
||||
.build();
|
||||
final WorkspaceConfigImpl config = createWorkspaceConfig("test");
|
||||
stack.setWorkspaceConfig(config);
|
||||
return stack;
|
||||
|
|
|
|||
|
|
@ -28,12 +28,12 @@ import org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl;
|
|||
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl;
|
||||
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl;
|
||||
import org.eclipse.che.api.workspace.server.spi.WorkspaceDao;
|
||||
import org.eclipse.che.commons.test.tck.TckModuleFactory;
|
||||
import org.eclipse.che.commons.test.tck.TckListener;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepository;
|
||||
import org.eclipse.che.commons.test.tck.repository.TckRepositoryException;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Listeners;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -54,7 +54,7 @@ import static org.testng.Assert.assertTrue;
|
|||
*
|
||||
* @author Yevhenii Voevodin
|
||||
*/
|
||||
@Guice(moduleFactory = TckModuleFactory.class)
|
||||
@Listeners(TckListener.class)
|
||||
@Test(suiteName = WorkspaceDaoTest.SUITE_NAME)
|
||||
public class WorkspaceDaoTest {
|
||||
|
||||
|
|
@ -188,7 +188,7 @@ public class WorkspaceDaoTest {
|
|||
|
||||
@Test
|
||||
public void shouldPublicRemoveWorkspaceEventAfterRemoveWorkspace() throws Exception {
|
||||
final boolean[] isNotified = new boolean[] { false };
|
||||
final boolean[] isNotified = new boolean[] {false};
|
||||
eventService.subscribe(event -> isNotified[0] = true, WorkspaceRemovedEvent.class);
|
||||
|
||||
workspaceDao.remove(workspaces[0].getId());
|
||||
|
|
|
|||
Loading…
Reference in New Issue