本文整理汇总了Java中org.springframework.test.annotation.Rollback类的典型用法代码示例。如果您正苦于以下问题:Java Rollback类的具体用法?Java Rollback怎么用?Java Rollback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Rollback类属于org.springframework.test.annotation包,在下文中一共展示了Rollback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBulkUpdate
import org.springframework.test.annotation.Rollback; //导入依赖的package包/类
@Test
@Transactional
@Rollback
public void testBulkUpdate() {
PropertyBox box = PropertyBox.builder(PROPS).set(KEY, 10L).set(STR, "k10").set(NBOOL, false).build();
getDatastore().save(NAMED_TARGET, box);
box = PropertyBox.builder(PROPS).set(KEY, 11L).set(STR, "k11").set(NBOOL, false).build();
getDatastore().save(NAMED_TARGET, box);
box = PropertyBox.builder(PROPS).set(KEY, 12L).set(STR, "k12").set(NBOOL, false).build();
getDatastore().save(NAMED_TARGET, box);
OperationResult result = getDatastore().bulkUpdate(NAMED_TARGET).filter(KEY.between(10L, 12L)).set(STR, "UPD")
.setNull(DAT).execute();
assertEquals(3, result.getAffectedCount());
List<String> values = getDatastore().query().target(NAMED_TARGET).filter(KEY.between(10L, 12L)).list(STR);
assertEquals(3, values.size());
values.forEach(v -> assertEquals("UPD", v));
result = getDatastore().bulkDelete(NAMED_TARGET).filter(KEY.between(10L, 12L)).execute();
assertEquals(3, result.getAffectedCount());
}
示例2: testReadSegmentsWithXInfoTest
import org.springframework.test.annotation.Rollback; //导入依赖的package包/类
@Test
@Transactional(readOnly=false)
@Rollback(value=true)
public void testReadSegmentsWithXInfoTest() {
String viewName = "gip_at_frc_0_4_xinfo_test";
OutputStream os = new ByteArrayOutputStream();
ISegmentOutputFormat<IWaySegment> graphOutputFormat;
graphOutputFormat = (ISegmentOutputFormat<IWaySegment>) segmentOutputFormatFactory.getSegmentOutputFormat(os);
try {
dao.streamSegments(graphOutputFormat, null, viewName, new Date());
} catch (GraphNotExistsException | WaySegmentSerializationException e) {
log.error("",e);
}
}
示例3: testGraphVersionMetadataDaoForSynchronizationAPI
import org.springframework.test.annotation.Rollback; //导入依赖的package包/类
@Test
@Transactional(readOnly=false)
@Rollback(true)
public void testGraphVersionMetadataDaoForSynchronizationAPI() {
String graphName = "gip_at_frc_0_4";
String version = "15_02_150401";
String newerVersion = dao.checkNewerVersionAvailable(graphName, version);
System.out.println("\nFür Graph '" + graphName + "' und Version '" + version + "' ist " +
newerVersion + " neue Version verfügbar");
version = "15_02_150402";
newerVersion = dao.checkNewerVersionAvailable(graphName, version);
System.out.println("\nFür Graph '" + graphName + "' und Version '" + version + "' ist " +
newerVersion + " neue Version verfügbar");
}
示例4: testCreateValidSubscriptionForDefaultView
import org.springframework.test.annotation.Rollback; //导入依赖的package包/类
@Test
@Transactional(readOnly=false)
@Rollback(value=true)
public void testCreateValidSubscriptionForDefaultView() {
String graphName = "gip_at";
String version = "1";
IWayGraph wayGraph = saveWayGraph(graphName, version);
viewDao.saveDefaultView(wayGraph);
ISubscription subscription = new Subscription("test_server", graphName, "http://irgend.wo", "user", "pwd", new Date());
List<ISubscription> subscriptions = new ArrayList<>();
subscriptions.add(subscription);
ISubscriptionGroup subscriptionGroup = new SubscriptionGroup(100, graphName, wayGraph, subscriptions);
subscription.setSubscriptionGroup(subscriptionGroup);
try {
subscriptionService.subscribeOnView(subscription);
} catch (GraphNotExistsException | SubscriptionFailedException e) {
log.error(e.getMessage(), e);
}
}
示例5: testCreateValidSubscriptionForCustomView
import org.springframework.test.annotation.Rollback; //导入依赖的package包/类
@Test
@Transactional(readOnly=false)
@Rollback(false)
public void testCreateValidSubscriptionForCustomView() {
String graphName = "gip_at";
String version = "1";
String viewName = "gip_at_sub";
IWayGraph wayGraph = saveWayGraph(graphName, version);
saveView(wayGraph, viewName, version);
ISubscription subscription = new Subscription("test_server", viewName, "http://irgend.wo", "user", "pwd", new Date());
List<ISubscription> subscriptions = new ArrayList<>();
subscriptions.add(subscription);
ISubscriptionGroup subscriptionGroup = new SubscriptionGroup(100, graphName, wayGraph, subscriptions);
subscription.setSubscriptionGroup(subscriptionGroup);
try {
subscriptionService.subscribeOnView(subscription);
} catch (GraphNotExistsException | SubscriptionFailedException e) {
log.error(e.getMessage(), e);
}
}
示例6: dismissCourseTest
import org.springframework.test.annotation.Rollback; //导入依赖的package包/类
@Test
@Rollback
public void dismissCourseTest() throws Exception {
mockMvc.perform(
post("/student/recommended")
.with(user(studentUserAccount))
.with(csrf())
.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)
.content("dismissedId="+calculusWS2016.getId())
).andExpect(
result -> {
if (studentRepository.findByAccount(studentUserAccount).getDismissedCourses().size() <= 0) {
throw new Exception("Size of dismissed courses for student " + student + " is zero");
}
if (!studentRepository.findByAccount(studentUserAccount).getDismissedCourses().contains(calculusWS2016)) {
throw new Exception("Wrong dismissed course!");
}
}
).andExpect(
redirectedUrl("/student/recommended")
);
}
示例7: setUp
import org.springframework.test.annotation.Rollback; //导入依赖的package包/类
@Before // a test
@Rollback(true)
public void setUp() throws Exception {
// System.out.println("Methode setUp");
try {
// save a couple of ToDoLists with rollback for tests.
repository.save(new ToDoList("Carotte"));
repository.save(new ToDoList("Lait"));
repository.save(new ToDoList("Chocolat"));
//Creation d'une liste depuis le service
// displayTable();
} catch (Exception ex) {
System.out.println("Exception : " + ex.getCause());
}
}
示例8: testBulkInsert
import org.springframework.test.annotation.Rollback; //导入依赖的package包/类
@Test
@Transactional
@Rollback
public void testBulkInsert() {
OperationResult result = getDatastore().bulkInsert(ENTITY_TARGET, PropertySet.of(KEY, STR))
.add(PropertyBox.builder(KEY, STR).set(KEY, 201L).set(STR, "Test bulk 201").build())
.add(PropertyBox.builder(KEY, STR).set(KEY, 202L).set(STR, "Test bulk 202").build())
.add(PropertyBox.builder(KEY, STR).set(KEY, 203L).set(STR, "Test bulk 203").build())
.add(PropertyBox.builder(KEY, STR).set(KEY, 204L).set(STR, "Test bulk 204").build())
.add(PropertyBox.builder(KEY, STR).set(KEY, 205L).set(STR, "Test bulk 205").build())
.add(PropertyBox.builder(KEY, STR).set(KEY, 206L).set(STR, "Test bulk 206").build())
.add(PropertyBox.builder(KEY, STR).set(KEY, 207L).set(STR, "Test bulk 207").build())
.add(PropertyBox.builder(KEY, STR).set(KEY, 208L).set(STR, "Test bulk 208").build())
.add(PropertyBox.builder(KEY, STR).set(KEY, 209L).set(STR, "Test bulk 209").build())
.add(PropertyBox.builder(KEY, STR).set(KEY, 210L).set(STR, "Test bulk 210").build()).execute();
assertEquals(10, result.getAffectedCount());
}
示例9: testCustomFilter
import org.springframework.test.annotation.Rollback; //导入依赖的package包/类
@Test
@Transactional
@Rollback
public void testCustomFilter() {
long count = getDatastore().query().target(ENTITY_TARGET).filter(new KeyIs(1)).count();
assertEquals(1, count);
Optional<String> str = getDatastore().query().target(NAMED_TARGET).filter(new KeyIs(1)).findOne(STR);
assertEquals("One", str.get());
OperationResult result = getDatastore().bulkUpdate(ENTITY_TARGET).set(ENM, TestEnum.THIRD).filter(new KeyIs(1))
.execute();
assertEquals(1, result.getAffectedCount());
Optional<PropertyBox> pb = getDatastore().query().target(ENTITY_TARGET).filter(new KeyIs(1)).findOne(PROPS);
assertEquals(TestEnum.THIRD, pb.get().getValue(ENM));
result = getDatastore().bulkUpdate(ENTITY_TARGET).filter(new KeyIs(2)).setNull(DAT).execute();
assertEquals(1, result.getAffectedCount());
pb = getDatastore().query().target(ENTITY_TARGET).filter(new KeyIs(2)).findOne(PROPS);
assertFalse(pb.get().containsValue(DAT));
}
示例10: testGeneratedId
import org.springframework.test.annotation.Rollback; //导入依赖的package包/类
@Test
@Transactional
@Rollback
public void testGeneratedId() {
final PathProperty<Long> CODE = PathProperty.create("code", Long.class);
final PathProperty<String> VALUE = PathProperty.create("value", String.class);
final DataTarget<TestGeneratedId> TARGET = JpaTarget.of(TestGeneratedId.class);
OperationResult result = getDatastore().insert(TARGET,
PropertyBox.builder(CODE, VALUE).set(VALUE, "Test value").build(), JpaWriteOption.FLUSH);
assertEquals(1, result.getAffectedCount());
assertEquals(1, result.getInsertedKeys().size());
assertEquals(Long.valueOf(1), result.getInsertedKeys().values().iterator().next());
// bring back ids
PropertyBox box = PropertyBox.builder(CODE, VALUE).set(VALUE, "Test v2").build();
result = getDatastore().insert(TARGET, box, JpaWriteOption.FLUSH, DefaultWriteOption.BRING_BACK_GENERATED_IDS);
assertEquals(1, result.getAffectedCount());
assertEquals(1, result.getInsertedKeys().size());
assertEquals(Long.valueOf(2), box.getValue(CODE));
}
示例11: testSaveDelete
import org.springframework.test.annotation.Rollback; //导入依赖的package包/类
@Test
@Transactional
@Rollback
public void testSaveDelete() {
// insert
PropertyBox box = PropertyBox.builder(PROPS).set(KEY, 3L).set(STR, "Three").set(NBOOL, false)
.set(ENM, TestEnum.THIRD).build();
getDatastore().save(NAMED_TARGET, box);
PropertyBox saved = getDatastore().query().target(NAMED_TARGET).filter(KEY.eq(3L)).findOne(PROPS).orElse(null);
assertNotNull(saved);
assertEquals("Three", saved.getValue(STR));
// update
saved.setValue(STR, "Three UPD");
getDatastore().save(NAMED_TARGET, saved);
saved = getDatastore().query().target(NAMED_TARGET).filter(KEY.eq(3L)).findOne(PROPS).orElse(null);
assertNotNull(saved);
assertEquals("Three UPD", saved.getValue(STR));
// delete
OperationResult deleted = getDatastore().delete(NAMED_TARGET, box);
assertTrue(deleted.getAffectedCount() == 1);
}
示例12: testCreateAndFindInstance
import org.springframework.test.annotation.Rollback; //导入依赖的package包/类
@Test
@Rollback
public void testCreateAndFindInstance() throws Exception {
String someAppId = "someAppId";
String someClusterName = "someClusterName";
String someDataCenter = "someDataCenter";
String someIp = "someIp";
Instance instance = instanceService.findInstance(someAppId, someClusterName, someDataCenter,
someIp);
assertNull(instance);
instanceService.createInstance(assembleInstance(someAppId, someClusterName, someDataCenter,
someIp));
instance = instanceService.findInstance(someAppId, someClusterName, someDataCenter,
someIp);
assertNotEquals(0, instance.getId());
}
示例13: testFindInstancesByIds
import org.springframework.test.annotation.Rollback; //导入依赖的package包/类
@Test
@Rollback
public void testFindInstancesByIds() throws Exception {
String someAppId = "someAppId";
String someClusterName = "someClusterName";
String someDataCenter = "someDataCenter";
String someIp = "someIp";
String anotherIp = "anotherIp";
Instance someInstance = instanceService.createInstance(assembleInstance(someAppId,
someClusterName, someDataCenter, someIp));
Instance anotherInstance = instanceService.createInstance(assembleInstance(someAppId,
someClusterName, someDataCenter, anotherIp));
List<Instance> instances = instanceService.findInstancesByIds(Sets.newHashSet(someInstance
.getId(), anotherInstance.getId()));
Set<String> ips = instances.stream().map(Instance::getIp).collect(Collectors.toSet());
assertEquals(2, instances.size());
assertEquals(Sets.newHashSet(someIp, anotherIp), ips);
}
示例14: testInsert
import org.springframework.test.annotation.Rollback; //导入依赖的package包/类
@Rollback(false)
public void testInsert() throws Exception {
Product item = new Product();
item.setProductId(IdUtils.uuid2());
item.setProductName("aa");
item.setProductCode(DateUtils.currentDate() + "01");
item.setPrice(50.2);
item.setCategoryId(new Long(2));
item.setDescription("bb");
item.setScore(20);
service.create(item);
Product item2 = new Product();
item2.setProductId(IdUtils.uuid2());
item2.setProductName("cc");
item2.setProductCode(DateUtils.currentDate() + "02");
item2.setPrice(20);
item2.setCategoryId(new Long(3));
item2.setDescription("dd");
item2.setScore(20);
service.create(item2);
// assertEquals("", size + 2, 30);
}
示例15: isDefaultRollback
import org.springframework.test.annotation.Rollback; //导入依赖的package包/类
/**
* Determine whether or not to rollback transactions by default for the
* supplied {@linkplain TestContext test context}.
* <p>Supports {@link Rollback @Rollback} or
* {@link TransactionConfiguration @TransactionConfiguration} at the
* class-level.
* @param testContext the test context for which the default rollback flag
* should be retrieved
* @return the <em>default rollback</em> flag for the supplied test context
* @throws Exception if an error occurs while determining the default rollback flag
*/
@SuppressWarnings("deprecation")
protected final boolean isDefaultRollback(TestContext testContext) throws Exception {
Class<?> testClass = testContext.getTestClass();
Rollback rollback = findAnnotation(testClass, Rollback.class);
boolean rollbackPresent = (rollback != null);
TransactionConfigurationAttributes txConfigAttributes = retrieveConfigurationAttributes(testContext);
if (rollbackPresent && txConfigAttributes != defaultTxConfigAttributes) {
throw new IllegalStateException(String.format("Test class [%s] is annotated with both @Rollback "
+ "and @TransactionConfiguration, but only one is permitted.", testClass.getName()));
}
if (rollbackPresent) {
boolean defaultRollback = rollback.value();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Retrieved default @Rollback(%s) for test class [%s].", defaultRollback,
testClass.getName()));
}
return defaultRollback;
}
// else
return txConfigAttributes.isDefaultRollback();
}