org.springframework.test.annotation.Commit Java Examples

The following examples show how to use org.springframework.test.annotation.Commit. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProgrammaticTxMgmtTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
@Commit
public void rollbackTxAndStartNewTxWithDefaultCommitSemantics() {
	assertInTransaction(true);
	assertTrue(TestTransaction.isActive());
	assertUsers("Dilbert");
	deleteFromTables("user");
	assertUsers();

	// Rollback
	TestTransaction.flagForRollback();
	assertTrue(TestTransaction.isFlaggedForRollback());
	TestTransaction.end();
	assertFalse(TestTransaction.isActive());
	assertInTransaction(false);
	assertUsers("Dilbert");

	// Start new transaction with default commit semantics
	TestTransaction.start();
	assertInTransaction(true);
	assertFalse(TestTransaction.isFlaggedForRollback());
	assertTrue(TestTransaction.isActive());

	executeSqlScript("classpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false);
	assertUsers("Dilbert", "Dogbert");
}
 
Example #2
Source File: ProgrammaticTxMgmtTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
@Commit
public void rollbackTxAndStartNewTxWithDefaultCommitSemantics() {
	assertInTransaction(true);
	assertTrue(TestTransaction.isActive());
	assertUsers("Dilbert");
	deleteFromTables("user");
	assertUsers();

	// Rollback
	TestTransaction.flagForRollback();
	assertTrue(TestTransaction.isFlaggedForRollback());
	TestTransaction.end();
	assertFalse(TestTransaction.isActive());
	assertInTransaction(false);
	assertUsers("Dilbert");

	// Start new transaction with default commit semantics
	TestTransaction.start();
	assertInTransaction(true);
	assertFalse(TestTransaction.isFlaggedForRollback());
	assertTrue(TestTransaction.isActive());

	executeSqlScript("classpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false);
	assertUsers("Dilbert", "Dogbert");
}
 
Example #3
Source File: BaseNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Commit
@Test
public void testDuplicateChildAssocCleanup() throws Exception
{
    Map<QName, ChildAssociationRef> assocRefs = buildNodeGraph();
    NodeRef n1Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE,"root_p_n1")).getChildRef();
    ChildAssociationRef n1pn3Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE,"n1_p_n3"));
    // Recreate the association from n1 to n3 i.e. duplicate it
    QName assocQName = QName.createQName(BaseNodeServiceTest.NAMESPACE, "dup");
    ChildAssociationRef dup1 = nodeService.addChild(
            n1pn3Ref.getParentRef(),
            n1pn3Ref.getChildRef(),
            n1pn3Ref.getTypeQName(),
            assocQName);
    ChildAssociationRef dup2 = nodeService.addChild(
            n1pn3Ref.getParentRef(),
            n1pn3Ref.getChildRef(),
            n1pn3Ref.getTypeQName(),
            assocQName);
    assertEquals("Duplicate not created", dup1, dup2);
    List<ChildAssociationRef> dupAssocs = nodeService.getChildAssocs(n1pn3Ref.getParentRef(), n1pn3Ref.getTypeQName(), assocQName);
    assertEquals("Expected duplicates", 2, dupAssocs.size());
    // Now delete the specific association
    nodeService.removeChildAssociation(dup1);
}
 
Example #4
Source File: ProgrammaticTxMgmtTestNGTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
@Commit
public void rollbackTxAndStartNewTxWithDefaultCommitSemantics() {
	assertInTransaction(true);
	assertTrue(TestTransaction.isActive());
	assertUsers("Dilbert");
	deleteFromTables("user");
	assertUsers();

	// Rollback
	TestTransaction.flagForRollback();
	assertTrue(TestTransaction.isFlaggedForRollback());
	TestTransaction.end();
	assertFalse(TestTransaction.isActive());
	assertInTransaction(false);
	assertUsers("Dilbert");

	// Start new transaction with default commit semantics
	TestTransaction.start();
	assertInTransaction(true);
	assertFalse(TestTransaction.isFlaggedForRollback());
	assertTrue(TestTransaction.isActive());

	executeSqlScript("classpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false);
	assertUsers("Dilbert", "Dogbert");
}
 
Example #5
Source File: BaseNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test <a href="https://issues.alfresco.com/jira/browse/ALFCOM-2299">ALFCOM-2299</a>
 * <p>Needs to be committed for good measure</p>
 */
@Commit
@Test
public void testAspectRemovalCascadeDelete() throws Exception
{
    // Create a node to add the aspect to
    NodeRef sourceNodeRef = nodeService.createNode(
            rootNodeRef,
            ASSOC_TYPE_QNAME_TEST_CHILDREN,
            QName.createQName(BaseNodeServiceTest.NAMESPACE, "testAspectRemovalCascadeDelete"),
            ContentModel.TYPE_CONTAINER).getChildRef();
    
    // Add the aspect to the source node and add a child using an association defined on the aspect
    nodeService.addAspect(sourceNodeRef, ASPECT_WITH_ASSOCIATIONS, null);
    NodeRef targetNodeRef = nodeService.createNode(
            sourceNodeRef,
            ASSOC_ASPECT_CHILD_ASSOC,
            QName.createQName(BaseNodeServiceTest.NAMESPACE, "testAspectRemovalCascadeDelete"),
            ContentModel.TYPE_CONTAINER).getChildRef();
    
    assertTrue("Child node must exist", nodeService.exists(targetNodeRef));
    // Now remove the aspect from the source node and check that the target node was cascade-deleted
    nodeService.removeAspect(sourceNodeRef, ASPECT_WITH_ASSOCIATIONS);
    assertFalse("Child node must have been cascade-deleted", nodeService.exists(targetNodeRef));
}
 
Example #6
Source File: RepositoryExporterComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Ignore
@Commit
@Test
public void testRepositoryExport()
{
    // Create a temp store to hold exports
    StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    NodeRef rootNode = nodeService.getRootNode(storeRef);
    FileInfo container = fileFolderService.create(rootNode, "export", ContentModel.TYPE_FOLDER);

    // Export stores
    RepositoryExportHandle[] handles = repositoryService.export(container.getNodeRef(), "test");
    assertNotNull(handles);
    assertEquals(6, handles.length);
    for (RepositoryExportHandle handle : handles)
    {
        assertTrue(nodeService.exists(handle.exportFile));
    }
}
 
Example #7
Source File: UserTest.java    From personal_book_library_web_project with MIT License 6 votes vote down vote up
@Test
@Transactional
@Commit
public void createUser() {
	
	User user = new User();
	user.setName("batuhan");
	user.setSurname("düzgün");
	user.setNickName("batux");
	user.setPassword(CryptoUtil.cryptPassword("12345"));
	user.setCreateDate(new Date());

	user = userRepository.save(user);
	
	Assert.assertNotNull(user.getId());
}
 
Example #8
Source File: ProgrammaticTxMgmtTestNGTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
@Commit
public void rollbackTxAndStartNewTxWithDefaultCommitSemantics() {
	assertInTransaction(true);
	assertTrue(TestTransaction.isActive());
	assertUsers("Dilbert");
	deleteFromTables("user");
	assertUsers();

	// Rollback
	TestTransaction.flagForRollback();
	assertTrue(TestTransaction.isFlaggedForRollback());
	TestTransaction.end();
	assertFalse(TestTransaction.isActive());
	assertInTransaction(false);
	assertUsers("Dilbert");

	// Start new transaction with default commit semantics
	TestTransaction.start();
	assertInTransaction(true);
	assertFalse(TestTransaction.isFlaggedForRollback());
	assertTrue(TestTransaction.isActive());

	executeSqlScript("classpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false);
	assertUsers("Dilbert", "Dogbert");
}
 
Example #9
Source File: ProgrammaticTxMgmtTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
@Commit
public void rollbackTxAndStartNewTxWithDefaultCommitSemantics() {
	assertInTransaction(true);
	assertTrue(TestTransaction.isActive());
	assertUsers("Dilbert");
	deleteFromTables("user");
	assertUsers();

	// Rollback
	TestTransaction.flagForRollback();
	assertTrue(TestTransaction.isFlaggedForRollback());
	TestTransaction.end();
	assertFalse(TestTransaction.isActive());
	assertInTransaction(false);
	assertUsers("Dilbert");

	// Start new transaction with default commit semantics
	TestTransaction.start();
	assertInTransaction(true);
	assertFalse(TestTransaction.isFlaggedForRollback());
	assertTrue(TestTransaction.isActive());

	executeSqlScript("classpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false);
	assertUsers("Dilbert", "Dogbert");
}
 
Example #10
Source File: ProgrammaticTxMgmtTestNGTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
@Commit
public void rollbackTxAndStartNewTxWithDefaultCommitSemantics() {
	assertInTransaction(true);
	assertTrue(TestTransaction.isActive());
	assertUsers("Dilbert");
	deleteFromTables("user");
	assertUsers();

	// Rollback
	TestTransaction.flagForRollback();
	assertTrue(TestTransaction.isFlaggedForRollback());
	TestTransaction.end();
	assertFalse(TestTransaction.isActive());
	assertInTransaction(false);
	assertUsers("Dilbert");

	// Start new transaction with default commit semantics
	TestTransaction.start();
	assertInTransaction(true);
	assertFalse(TestTransaction.isFlaggedForRollback());
	assertTrue(TestTransaction.isActive());

	executeSqlScript("classpath:/org/springframework/test/context/jdbc/data-add-dogbert.sql", false);
	assertUsers("Dilbert", "Dogbert");
}
 
Example #11
Source File: BookTest.java    From personal_book_library_web_project with MIT License 5 votes vote down vote up
@Test
@Transactional
@Commit
public void listBooksByUserId() {
	
	Book book1 = prepareBook();
	book1 = bookRepository.save(book1);
	
	Long userId = book1.getUser().getId();
	List<Book> booksOfUser = bookRepository.findByUser(userId);
	
	Assert.assertTrue(!CollectionUtils.isEmpty(booksOfUser));
}
 
Example #12
Source File: BaseNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Commit
@Test
public void testLocalizedAspect() throws Exception
{
    nodeService.addAspect(
            rootNodeRef,
            ContentModel.ASPECT_LOCALIZED,
            Collections.<QName, Serializable>singletonMap(ContentModel.PROP_LOCALE, Locale.CANADA_FRENCH));
    // commit to check
}
 
Example #13
Source File: SpringBootstrappingTest.java    From HibernateTips with MIT License 5 votes vote down vote up
@Test
@Transactional
@Commit
public void accessHibernateSession() {
	log.info("... accessHibernateSession ...");
	
	Author a = new Author();
	a.setFirstName("Thorben");
	a.setLastName("Janssen");
	em.persist(a);
}
 
Example #14
Source File: DynamicUpdateIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
@Commit
// Enable Hibernate's debug logging in logback.xml to see the generated SQL statement.
public void testB_whenAccountNameUpdated_thenSuccess() {
    Account account = accountRepository.findOne(ACCOUNT_ID);
    account.setName("Test Account");
    accountRepository.save(account);
}
 
Example #15
Source File: HibernateSearchIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Commit
@Test
public void testA_whenInitialTestDataInserted_thenSuccess() {

    for (int i = 0; i < products.size() - 1; i++) {
        entityManager.persist(products.get(i));
    }
}
 
Example #16
Source File: AbstractInvitationServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Commit
public void disabled_test100Invites() throws Exception
{
    Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
    String resourceName = SITE_SHORT_NAME_INVITE;
    String inviteeRole = SiteModel.SITE_COLLABORATOR;
    String serverPath = "wibble";
    String acceptUrl = "froob";
    String rejectUrl = "marshmallow";

    authenticationComponent.setCurrentUser(USER_MANAGER);

    // Create 1000 invites
    for (int i = 0; i < 1000; i++)
    {
        invitationService.inviteNominated(USER_ONE, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
    }
    
    // Invite USER_TWO 
    NominatedInvitation invite = invitationService.inviteNominated(USER_TWO, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
    
    InvitationSearchCriteriaImpl query = new InvitationSearchCriteriaImpl();
    query.setInvitee(USER_TWO);
    
    long start = System.currentTimeMillis();
    List<Invitation> results = invitationService.searchInvitation(query);
    long end= System.currentTimeMillis();
    System.out.println("Invitation Search took " + (end - start) + "ms.");
    
    assertEquals(1, results.size());
    assertEquals(invite.getInviteId(), results.get(0).getInviteId());
}
 
Example #17
Source File: VersionServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Test reverting from Share with changing type
 * see MNT-14688
 * <li>
 *     <ul>1) Create a node and a version (simulates upload a doc to Share)</ul>
 *     <ul>2) Change the node's type to a custom with mandatory aspect</ul>
 *     <ul>3) Create a new version via upload</ul>
 *     <ul>4) Try to revert to original document and see if the type is reverted, too</ul>
 * </li>
 */
@SuppressWarnings("unused")
@Commit
@Test
public void testScriptNodeRevertWithChangeType()
{
    CheckOutCheckInService checkOutCheckInService =
            (CheckOutCheckInService) applicationContext.getBean("checkOutCheckInService");

    // Create a versionable node
    NodeRef versionableNode = createNewVersionableNode();
    Version version1 = createVersion(versionableNode);
    //Set new type
    nodeService.setType(versionableNode, TEST_TYPE_WITH_MANDATORY_ASPECT_QNAME);
    // Create a new version
    NodeRef checkedOut = checkOutCheckInService.checkout(versionableNode);
    ContentWriter contentWriter = this.contentService.getWriter(checkedOut, ContentModel.PROP_CONTENT, true);
    assertNotNull(contentWriter);
    contentWriter.putContent(UPDATED_CONTENT_1);
    nodeService.setProperty(checkedOut, PROP_1, VALUE_1);
    checkOutCheckInService.checkin(checkedOut, null, contentWriter.getContentUrl(), false);
    Version version2 = createVersion(versionableNode);

    // Create a ScriptNode as used in Share
    ServiceRegistry services = applicationContext.getBean(ServiceRegistry.class);
    ScriptNode scriptNode = new ScriptNode(versionableNode, services);
    assertEquals("0.2", nodeService.getProperty(scriptNode.getNodeRef(), ContentModel.PROP_VERSION_LABEL));
    assertEquals(TEST_TYPE_WITH_MANDATORY_ASPECT_QNAME, nodeService.getType(scriptNode.getNodeRef()));

    // Revert to version1
    ScriptNode newNode = scriptNode.revert("History", false, version1.getVersionLabel());
    assertEquals("0.3", nodeService.getProperty(newNode.getNodeRef(), ContentModel.PROP_VERSION_LABEL));
    assertEquals(TEST_TYPE_QNAME, nodeService.getType(newNode.getNodeRef()));
}
 
Example #18
Source File: BookTest.java    From personal_book_library_web_project with MIT License 5 votes vote down vote up
@Test
@Transactional
@Commit
public void createBook() {
	
	Book book1 = prepareBook();
	book1 = bookRepository.save(book1);
	
	Assert.assertNotNull(book1.getId());
}
 
Example #19
Source File: CategoryTest.java    From personal_book_library_web_project with MIT License 5 votes vote down vote up
@Test
@Transactional
@Commit
public void createCategory() {
	
	Category category = new Category();
	category.setName("Edebiyat");
	category = categoryRepository.save(category);
	
	Assert.assertNotNull(category.getId());
}
 
Example #20
Source File: BookTest.java    From personal_book_library_web_project with MIT License 5 votes vote down vote up
@Test
@Transactional
@Commit
public void createBookAndSendEmail() {
	
	Book book1 = prepareBook();
	book1 = bookRepository.save(book1);
	
	mailMessageProducer.send(MailContextUtil.createMailContext(book1, environment.getProperty("to.emails")));
	
	Assert.assertNotNull(book1.getId());
}
 
Example #21
Source File: HibernateSearchIntegrationTest.java    From tutorials with MIT License 4 votes vote down vote up
@Commit
@Test
public void testC_whenAdditionalTestDataInserted_thenSuccess() {

    entityManager.persist(products.get(products.size() - 1));
}
 
Example #22
Source File: DynamicUpdateIntegrationTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
@Commit
public void testA_whenTestAccountIsSaved_thenSuccess() {
    Account account = new Account(ACCOUNT_ID, "account1", "regional", true);
    accountRepository.save(account);
}
 
Example #23
Source File: TransactionalTestExecutionListenerTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Commit
public void test() {
}
 
Example #24
Source File: TransactionalTestExecutionListenerTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Commit
public void test() {
}
 
Example #25
Source File: CallbackConsumerTest.java    From galeb with Apache License 2.0 4 votes vote down vote up
@Before
@Commit
public void init() {
    String userDir = System.getProperty("user.dir");
    String pathProjectGaleb = userDir.substring(0, userDir.lastIndexOf(File.separator));
    String pathProjectApi = File.separator + pathProjectGaleb +
            File.separator + "api" +
            File.separator + "src" +
            File.separator + "main"+
            File.separator + "resources" +
            File.separator + "db" +
            File.separator + "migration";
    FLYWAY.setLocations("filesystem:" + pathProjectApi);
    FLYWAY.setDataSource(dbUrl, dbUsername, dbPassword);
    FLYWAY.clean();
    FLYWAY.migrate();
    Environment env;

    env = new Environment();
    env.setId(Long.valueOf("1"));
    env.setName("env-name");
    entityManager.persist(env);

    BalancePolicy bp = new BalancePolicy();
    bp.setName("name-bp");
    entityManager.persist(bp);

    Project project = new Project();
    project.setName("name-project");
    entityManager.persist(project);

    Pool pool = new Pool();
    pool.setName("name-pool");
    pool.setBalancepolicy(bp);
    pool.setEnvironment(env);
    pool.setProject(project);
    entityManager.persist(pool);

    target = new Target();
    target.setName("http://127.0.0.1:8080");
    target.setPool(pool);
    entityManager.persist(target);
    entityManager.flush();
}
 
Example #26
Source File: BaseNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Commit
@Test
public void testPropertyLocaleBehaviour() throws Exception
{
    Map<QName, Serializable> properties = new HashMap<QName, Serializable>(17);
    properties.put(PROP_QNAME_BOOLEAN_VALUE, true);
    properties.put(PROP_QNAME_INTEGER_VALUE, 123);
    properties.put(PROP_QNAME_LONG_VALUE, 123L);
    properties.put(PROP_QNAME_FLOAT_VALUE, 123.0F);
    properties.put(PROP_QNAME_DOUBLE_VALUE, 123.0);
    properties.put(PROP_QNAME_STRING_VALUE, "123.0");
    properties.put(PROP_QNAME_ML_TEXT_VALUE, new MLText("This is ML text in the default language"));
    properties.put(PROP_QNAME_DATE_VALUE, new Date());
    // Get the check values
    Map<QName, Serializable> expectedProperties = new HashMap<QName, Serializable>(properties);
    getExpectedPropertyValues(expectedProperties);

    Locale.setDefault(Locale.JAPANESE);
    
    // create a new node
    NodeRef nodeRef = nodeService.createNode(
            rootNodeRef,
            ASSOC_TYPE_QNAME_TEST_CHILDREN,
            QName.createQName("pathA"),
            TYPE_QNAME_TEST_MANY_PROPERTIES,
            properties).getChildRef();
    
    // Check the properties again
    Map<QName, Serializable> checkProperties = nodeService.getProperties(nodeRef);
    checkProperties(checkProperties, expectedProperties);
    
    // Change the locale and set the properties again
    I18NUtil.setLocale(Locale.US);
    nodeService.setProperties(nodeRef, properties);

    // Check the properties again
    checkProperties = nodeService.getProperties(nodeRef);
    checkProperties(checkProperties, expectedProperties);
    
    // Change the locale and set the properties again
    I18NUtil.setLocale(Locale.UK);
    nodeService.setProperties(nodeRef, properties);

    // Check the properties again
    checkProperties = nodeService.getProperties(nodeRef);
    checkProperties(checkProperties, expectedProperties);
    
    // Change the locale and set the properties again
    I18NUtil.setLocale(Locale.US);
    nodeService.addProperties(nodeRef, properties);

    // Check the properties again
    checkProperties = nodeService.getProperties(nodeRef);
    checkProperties(checkProperties, expectedProperties);
    
    // Change the locale and set the properties again
    I18NUtil.setLocale(Locale.UK);
    nodeService.addProperties(nodeRef, properties);

    // Check the properties again
    checkProperties = nodeService.getProperties(nodeRef);
    checkProperties(checkProperties, expectedProperties);
    
    // Change the locale and set the properties again
    I18NUtil.setLocale(Locale.US);
    nodeService.setProperty(nodeRef, PROP_QNAME_DATE_VALUE, properties.get(PROP_QNAME_DATE_VALUE));

    // Check the properties again
    checkProperties = nodeService.getProperties(nodeRef);
    checkProperties(checkProperties, expectedProperties);
    
    // Change the locale and set the properties again
    I18NUtil.setLocale(Locale.UK);
    nodeService.setProperty(nodeRef, PROP_QNAME_DATE_VALUE, properties.get(PROP_QNAME_DATE_VALUE));

    // Check the properties again
    checkProperties = nodeService.getProperties(nodeRef);
    checkProperties(checkProperties, expectedProperties);
}
 
Example #27
Source File: BaseNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Commit
@Test
public void testDelete() throws Exception
{
    final List<NodeRef> beforeDeleteNodeRefs = new ArrayList<NodeRef>(5);
    final List<NodeRef> deletedNodeRefs = new ArrayList<NodeRef>(5);
    
    BadOnDeleteNodePolicy nasty = new BadOnDeleteNodePolicy(nodeService, beforeDeleteNodeRefs, deletedNodeRefs);
    nasty.setOnDeleteCreateChild(false);
    nasty.setBeforeDeleteCreateChild(false);
    NodeServicePolicies.OnDeleteNodePolicy policy = nasty;

    // bind to listen to the deletion of a node
    policyComponent.bindClassBehaviour(
            OnDeleteNodePolicy.QNAME,
            policy,
            new JavaBehaviour(policy, "onDeleteNode"));   
    
    policyComponent.bindClassBehaviour(
            BeforeDeleteNodePolicy.QNAME,
            policy,
            new JavaBehaviour(policy, "beforeDeleteNode"));   
    
    // build the node and commit the node graph
    Map<QName, ChildAssociationRef> assocRefs = buildNodeGraph(nodeService, rootNodeRef);
    NodeRef n1Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "root_p_n1")).getChildRef();
    NodeRef n3Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n1_p_n3")).getChildRef();
    NodeRef n4Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n2_p_n4")).getChildRef();
    NodeRef n6Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n3_p_n6")).getChildRef();
    NodeRef n8Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n6_p_n8")).getChildRef();
    
    // delete n1
    nodeService.deleteNode(n1Ref);
    assertFalse("Node not directly deleted", nodeService.exists(n1Ref));
    assertFalse("Node not cascade deleted", nodeService.exists(n3Ref));
    assertTrue("Node incorrectly cascade deleted", nodeService.exists(n4Ref));
    assertFalse("Node not cascade deleted", nodeService.exists(n6Ref));
    assertFalse("Node not cascade deleted", nodeService.exists(n8Ref));
    
    // check before delete delete policy has been called
    assertTrue("n1Ref before delete policy not called", beforeDeleteNodeRefs.contains(n1Ref));
    assertTrue("n3Ref before delete policy not called", beforeDeleteNodeRefs.contains(n3Ref));
    assertTrue("n6Ref before delete policy not called", beforeDeleteNodeRefs.contains(n6Ref));
    assertTrue("n8Ref before delete policy not called", beforeDeleteNodeRefs.contains(n8Ref));
    
    // check delete policy has been called
    assertTrue("n1Ref delete policy not called", deletedNodeRefs.contains(n1Ref));
    assertTrue("n3Ref delete policy not called", deletedNodeRefs.contains(n3Ref));
    assertTrue("n6Ref delete policy not called", deletedNodeRefs.contains(n6Ref));
    assertTrue("n8Ref delete policy not called", deletedNodeRefs.contains(n8Ref));
}
 
Example #28
Source File: BaseNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Commit
@Test
public void testDeleteStore() throws Exception
{
    StoreRef storeRef = createStore();
    NodeRef rootNodeRef = nodeService.getRootNode(storeRef);

    // Add a node into the store and listen for the node's deletion
    NodeRef nodeRef = nodeService.createNode(rootNodeRef,
            ASSOC_TYPE_QNAME_TEST_CHILDREN,
            QName.createQName("pathA"),
            ContentModel.TYPE_CONTAINER).getChildRef();
    List<NodeRef> beforeDeleteNodeRefs = new ArrayList<NodeRef>();
    List<NodeRef> onDeleteNodeRefs = new ArrayList<NodeRef>();
    BadOnDeleteNodePolicy policy = new BadOnDeleteNodePolicy(nodeService, beforeDeleteNodeRefs, onDeleteNodeRefs);
    policy.setOnDeleteCreateChild(false);
    policy.setBeforeDeleteCreateChild(false);
    policyComponent.bindClassBehaviour(
            OnDeleteNodePolicy.QNAME,
            policy,
            new JavaBehaviour(policy, "onDeleteNode"));   
    policyComponent.bindClassBehaviour(
            BeforeDeleteNodePolicy.QNAME,
            policy,
            new JavaBehaviour(policy, "beforeDeleteNode"));   
    
    // get all stores
    List<StoreRef> storeRefs = nodeService.getStores();
    // check that the store ref is present
    assertTrue("New store not present in list of stores", storeRefs.contains(storeRef));
    // Get the root node
    assertTrue("Store should still exist", nodeService.exists(storeRef));
    assertTrue("Node should still exist", nodeService.exists(rootNodeRef));
    // Delete it
    nodeService.deleteStore(storeRef);
    storeRefs = nodeService.getStores();
    assertFalse("Deleted store should not present in list of stores", storeRefs.contains(storeRef));
    // Now make sure that none of the stores have the "deleted" protocol
    for (StoreRef retrievedStoreRef : storeRefs)
    {
        if (retrievedStoreRef.getProtocol().equals(StoreRef.PROTOCOL_DELETED))
        {
            fail("NodeService should not have returned 'deleted' stores." + storeRefs);
        }
    }
    // They should not exist as far as external code is concerned
    assertFalse("Store should still exist", nodeService.exists(storeRef));
    assertFalse("Node should still exist", nodeService.exists(rootNodeRef));
    
    // Check that we received callbacks
    assertEquals("Incorrect number of node beforeDelete notifications", 1, beforeDeleteNodeRefs.size());
    assertEquals("Incorrect node for beforeDelete callback", nodeRef, beforeDeleteNodeRefs.get(0));
    assertEquals("Incorrect number of node onDelete notifications", 1, onDeleteNodeRefs.size());
    assertEquals("Incorrect node for onDelete callback", nodeRef, onDeleteNodeRefs.get(0));

    // Commit to ensure all is well
}
 
Example #29
Source File: RuleServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Commit
    @Test
    public void testCyclicAsyncRules() throws Exception
    {
        NodeRef nodeRef = createNewNode(this.rootNodeRef);
        
        // Create the first rule
        
        Map<String, Serializable> conditionProps = new HashMap<String, Serializable>();
        conditionProps.put(ComparePropertyValueEvaluator.PARAM_VALUE, "*.jpg");

        Map<String, Serializable> actionProps = new HashMap<String, Serializable>();
        actionProps.put(ImageTransformActionExecuter.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_IMAGE_GIF);
        actionProps.put(ImageTransformActionExecuter.PARAM_DESTINATION_FOLDER, nodeRef);
        actionProps.put(ImageTransformActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CHILDREN);
        actionProps.put(ImageTransformActionExecuter.PARAM_ASSOC_QNAME, ContentModel.ASSOC_CHILDREN);
        
        Rule rule = new Rule();
        rule.setRuleType(this.ruleType.getName());
        rule.setTitle("Convert from *.jpg to *.gif");
        rule.setExecuteAsynchronously(true);
        
        Action action = this.actionService.createAction(ImageTransformActionExecuter.NAME);
        action.setParameterValues(actionProps);
        
        ActionCondition actionCondition = this.actionService.createActionCondition(ComparePropertyValueEvaluator.NAME);
        actionCondition.setParameterValues(conditionProps);
        action.addActionCondition(actionCondition);        
        
        rule.setAction(action);
        
        // Create the next rule
        
        Map<String, Serializable> conditionProps2 = new HashMap<String, Serializable>();
        conditionProps2.put(ComparePropertyValueEvaluator.PARAM_VALUE, "*.gif");

        Map<String, Serializable> actionProps2 = new HashMap<String, Serializable>();
        actionProps2.put(ImageTransformActionExecuter.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_IMAGE_JPEG);
        actionProps2.put(ImageTransformActionExecuter.PARAM_DESTINATION_FOLDER, nodeRef);
        actionProps2.put(ImageTransformActionExecuter.PARAM_ASSOC_QNAME, ContentModel.ASSOC_CHILDREN);
        
        Rule rule2 = new Rule();
        rule2.setRuleType(this.ruleType.getName());
        rule2.setTitle("Convert from *.gif to *.jpg");
        rule2.setExecuteAsynchronously(true);
        
        Action action2 = this.actionService.createAction(ImageTransformActionExecuter.NAME);
        action2.setParameterValues(actionProps2);
        
        ActionCondition actionCondition2 = this.actionService.createActionCondition(ComparePropertyValueEvaluator.NAME);
        actionCondition2.setParameterValues(conditionProps2);
        action2.addActionCondition(actionCondition2);
        
        rule2.setAction(action2);
        
        // Save the rules
        this.ruleService.saveRule(nodeRef, rule);
        this.ruleService.saveRule(nodeRef, rule);
        
        // Now create new content
        NodeRef contentNode = this.nodeService.createNode(nodeRef,
                ContentModel.ASSOC_CHILDREN,
                QName.createQName("{test}testnode"),
                ContentModel.TYPE_CONTENT).getChildRef();
        this.nodeService.setProperty(contentNode, ContentModel.PROP_NAME, "myFile.jpg");
        File file = AbstractContentTransformerTest.loadQuickTestFile("jpg");
        ContentWriter writer = this.contentService.getWriter(contentNode, ContentModel.PROP_CONTENT, true);
        writer.setEncoding("UTF-8");
        writer.setMimetype(MimetypeMap.MIMETYPE_IMAGE_JPEG);
        writer.putContent(file);
        
        //final NodeRef finalNodeRef = nodeRef;
        
        // Check to see what has happened
//        ActionServiceImplTest.postAsyncActionTest(
//                this.transactionService,
//                10000, 
//                10, 
//                new AsyncTest()
//                {
//                    public boolean executeTest() 
//                    {
//                        List<ChildAssociationRef> assocs = RuleServiceImplTest.this.nodeService.getChildAssocs(finalNodeRef);
//                        for (ChildAssociationRef ref : assocs)
//                        {
//                            NodeRef child = ref.getChildRef();
//                            System.out.println("Child name: " + RuleServiceImplTest.this.nodeService.getProperty(child, ContentModel.PROP_NAME));
//                        }
//                        
//                        return true;
//                    };
//                });
    }
 
Example #30
Source File: VersionServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Test reverting from Share
 */
@SuppressWarnings("unused")
@Commit
@Test
public void testScriptNodeRevert()
{
    CheckOutCheckInService checkOutCheckIn =
        (CheckOutCheckInService) applicationContext.getBean("checkOutCheckInService");
    
    // Create a versionable node
    NodeRef versionableNode = createNewVersionableNode();
    NodeRef checkedOut = checkOutCheckIn.checkout(versionableNode);
    
    Version versionC1 = createVersion(checkedOut);

    
    // Create a new, first proper version
    ContentWriter contentWriter = this.contentService.getWriter(checkedOut, ContentModel.PROP_CONTENT, true);
    assertNotNull(contentWriter);
    contentWriter.putContent(UPDATED_CONTENT_1);
    nodeService.setProperty(checkedOut, PROP_1, VALUE_1);
    checkOutCheckIn.checkin(checkedOut, null, contentWriter.getContentUrl(), false);
    Version version1 = createVersion(versionableNode);
    checkedOut = checkOutCheckIn.checkout(versionableNode);
    
    
    // Create another new version
    contentWriter = this.contentService.getWriter(checkedOut, ContentModel.PROP_CONTENT, true);
    assertNotNull(contentWriter);
    contentWriter.putContent(UPDATED_CONTENT_2);
    nodeService.setProperty(checkedOut, PROP_1, VALUE_2);
    checkOutCheckIn.checkin(checkedOut, null, contentWriter.getContentUrl(), false);
    Version version2 = createVersion(versionableNode);
    checkedOut = checkOutCheckIn.checkout(versionableNode);
    
    // Check we're now up to two versions
    // (The version created on the working copy doesn't count)
    VersionHistory history = versionService.getVersionHistory(versionableNode);
    assertEquals(version2.getVersionLabel(), history.getHeadVersion().getVersionLabel());
    assertEquals(version2.getVersionedNodeRef(), history.getHeadVersion().getVersionedNodeRef());
    assertEquals(2, history.getAllVersions().size());
    
    Version[] versions = history.getAllVersions().toArray(new Version[2]);
    assertEquals("0.2", versions[0].getVersionLabel());
    assertEquals("0.1", versions[1].getVersionLabel());
    
    
    // Add yet another version
    contentWriter = this.contentService.getWriter(checkedOut, ContentModel.PROP_CONTENT, true);
    assertNotNull(contentWriter);
    contentWriter.putContent(UPDATED_CONTENT_3);
    nodeService.setProperty(checkedOut, PROP_1, VALUE_3);
    checkOutCheckIn.checkin(checkedOut, null, contentWriter.getContentUrl(), false);
    Version version3 = createVersion(versionableNode);
    
    // Verify that the version labels are as we expect them to be
    history = versionService.getVersionHistory(versionableNode);
    assertEquals(version3.getVersionLabel(), history.getHeadVersion().getVersionLabel());
    assertEquals(version3.getVersionedNodeRef(), history.getHeadVersion().getVersionedNodeRef());
    assertEquals(3, history.getAllVersions().size());
    
    versions = history.getAllVersions().toArray(new Version[3]);
    assertEquals("0.3", versions[0].getVersionLabel());
    assertEquals("0.2", versions[1].getVersionLabel());
    assertEquals("0.1", versions[2].getVersionLabel());
    
    
    // Create a ScriptNode as used in Share
    ServiceRegistry services = applicationContext.getBean(ServiceRegistry.class); 
    ScriptNode scriptNode = new ScriptNode(versionableNode, services);
    assertEquals("0.3", nodeService.getProperty(scriptNode.getNodeRef(), ContentModel.PROP_VERSION_LABEL));
    assertEquals(VALUE_3, nodeService.getProperty(scriptNode.getNodeRef(), PROP_1));
    
    // Revert to version2
    // The content and properties will be the same as on Version 2, but we'll
    //  actually be given a new version number for it
    ScriptNode newNode = scriptNode.revert("History", false, version2.getVersionLabel());
    ContentReader contentReader = this.contentService.getReader(newNode.getNodeRef(), ContentModel.PROP_CONTENT);
    assertNotNull(contentReader);
    assertEquals(UPDATED_CONTENT_2, contentReader.getContentString());
    assertEquals(VALUE_2, nodeService.getProperty(newNode.getNodeRef(), PROP_1));
    // Will be a new version though - TODO Is this correct?
    assertEquals("0.4", nodeService.getProperty(newNode.getNodeRef(), ContentModel.PROP_VERSION_LABEL));
    
    // Revert to version1
    newNode = scriptNode.revert("History", false, version1.getVersionLabel());
    contentReader = this.contentService.getReader(newNode.getNodeRef(), ContentModel.PROP_CONTENT);
    assertNotNull(contentReader);
    assertEquals(UPDATED_CONTENT_1, contentReader.getContentString());
    assertEquals(VALUE_1, nodeService.getProperty(newNode.getNodeRef(), PROP_1));
    // Will be a new version though - TODO Is this correct?
    assertEquals("0.5", nodeService.getProperty(newNode.getNodeRef(), ContentModel.PROP_VERSION_LABEL));
}