Skip to content

Commit

Permalink
Reproduce #393
Browse files Browse the repository at this point in the history
  • Loading branch information
frant-hartm committed Aug 28, 2017
1 parent bab913e commit 0743af6
Showing 1 changed file with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
* You may not use this product except in compliance with the License.
*
* This product may include a number of subcomponents with
* separate copyright notices and license terms. Your use of the source
* code for these subcomponents is subject to the terms and
* conditions of the subcomponent's license, as noted in the LICENSE file.
*/

package org.neo4j.ogm.persistence.transaction;

import java.io.IOException;
import java.util.Collections;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.neo4j.ogm.domain.simple.User;
import org.neo4j.ogm.model.Result;
import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
import org.neo4j.ogm.testutil.MultiDriverTestClass;

import static java.util.Collections.emptyMap;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Test of behaviour of the Session for default transactions (transactions without explicit handling)
*
* @author Frantisek Hartman
*/
public class DefaultTransactionTest extends MultiDriverTestClass {

private static final Logger logger = LoggerFactory.getLogger(DefaultTransactionTest.class);

private static SessionFactory sessionFactory;
private Session session;

@BeforeClass
public static void setUpClass() throws Exception {
sessionFactory = new SessionFactory(driver, "org.neo4j.ogm.domain.simple");
}

@Before
public void init() throws IOException {
session = sessionFactory.openSession();
Result result = session.query("CREATE CONSTRAINT ON (u:User) ASSERT u.name IS UNIQUE", emptyMap());
}

@After
public void tearDown() throws Exception {
session.query("DROP CONSTRAINT ON (u:User) ASSERT u.name IS UNIQUE", emptyMap());
}

@Test
public void shouldBeAbleToUseSessionAfterDefaultTransactionFails() throws Exception {

User u1 = new User("frantisek");
session.save(u1);
session.clear();

try {
session.save(new User("frantisek"));
} catch (Exception ex) {
logger.info("Caught exception", ex);
}

User loaded = session.load(User.class, u1.getId());
assertThat(loaded).isNotNull();
}
}

0 comments on commit 0743af6

Please sign in to comment.