gt:         nodeService.addAspect(n1, noderefAspect, properties3);
context: /*
   * #%L
   * Alfresco Repository
   * %%
   * Copyright (C) 2005 - 2016 Alfresco Software Limited
   * %%
   * This file is part of the Alfresco software. 
   * If the software was purchased under a paid Alfresco license, the terms of 
   * the paid license agreement will prevail.  Otherwise, the software is 
   * provided under the following open source license terms:
   * 
   * Alfresco is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Lesser General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   * 
   * Alfresco is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU Lesser General Public License for more details.
   * 
   * You should have received a copy of the GNU Lesser General Public License
   * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
   * #L%
   */
  package org.alfresco.repo.node;
  
  import java.io.InputStream;
  import java.io.Serializable;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.HashMap;
  
  import org.alfresco.model.ContentModel;
  import org.alfresco.repo.dictionary.DictionaryDAO;
  import org.alfresco.repo.dictionary.M2Model;
  import org.alfresco.repo.security.authentication.AuthenticationComponent;
  import org.alfresco.service.cmr.repository.NodeRef;
  import org.alfresco.service.cmr.repository.NodeService;
  import org.alfresco.service.cmr.repository.StoreRef;
  import org.alfresco.service.namespace.QName;
  import org.alfresco.test_category.BaseSpringTestsCategory;
  import org.alfresco.util.BaseSpringTest;
  import org.junit.After;
  import org.junit.Before;
  import org.junit.Test;
  import org.junit.experimental.categories.Category;
  import org.springframework.transaction.annotation.Transactional;
  
  @Category(BaseSpringTestsCategory.class)
  @Transactional
  public class NodeRefPropertyMethodInterceptorTest extends BaseSpringTest
  {
  
      private static final String TEST_NAMESPACE = "http://www.alfresco.org/test/NodeRefTestModel";
  
      private QName testType = QName.createQName(TEST_NAMESPACE, "testType");
  
      private QName categoryAspect = QName.createQName(TEST_NAMESPACE, "singleCategory");
  
      private QName categoriesAspect = QName.createQName(TEST_NAMESPACE, "multipleCategories");
  
      private QName noderefAspect = QName.createQName(TEST_NAMESPACE, "singleNodeRef");
  
      private QName noderefsAspect = QName.createQName(TEST_NAMESPACE, "multipleNodeRefs");
  
      private QName aspectCategoryProp = QName.createQName(TEST_NAMESPACE, "category");
  
      private QName aspectCategoriesProp = QName.createQName(TEST_NAMESPACE, "categories");
  
      private QName aspectNoderefProp = QName.createQName(TEST_NAMESPACE, "noderef");
  
      private QName aspectNoderefsProp = QName.createQName(TEST_NAMESPACE, "noderefs");
  
      private QName typeCategoryProp = QName.createQName(TEST_NAMESPACE, "category1");
  
      private QName typeCategoriesProp = QName.createQName(TEST_NAMESPACE, "categories1");
  
      private QName typeNoderefProp = QName.createQName(TEST_NAMESPACE, "noderef1");
  
      private QName typeNoderefsProp = QName.createQName(TEST_NAMESPACE, "noderefs1");
  
      private NodeService mlAwareNodeService;
  
      private NodeService nodeService;
  
      private NodeRef rootNodeRef;
  
      private AuthenticationComponent authenticationComponent;
  
      private DictionaryDAO dictionaryDAO;
  
      public NodeRefPropertyMethodInterceptorTest()
      {
          super();
      }
  
      @Before
      public void before() throws Exception
      {
          mlAwareNodeService = (NodeService) applicationContext.getBean("mlAwareNodeService");
          nodeService = (NodeService) applicationContext.getBean("nodeService");
          dictionaryDAO = (DictionaryDAO) applicationContext.getBean("dictionaryDAO");
  
          authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
  
          authenticationComponent.setSystemUserAsCurrentUser();
  
          ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
          InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/node/NodeRefTestModel.xml");
          assertNotNull(modelStream);
          M2Model model = M2Model.createModel(modelStream);
          dictionaryDAO.putModel(model);
  
          StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
          rootNodeRef = nodeService.getRootNode(storeRef);
  
      }
  
      @After
      public void after() throws Exception
      {
          try
          {
              authenticationComponent.clearCurrentSecurityContext();
          }
          catch (Throwable e)
          {
              // do nothing
          }
      }
  
      @Test
      public void testOnRead()
      {
          NodeRef invalidNodeRef = new NodeRef(rootNodeRef.getStoreRef(), "InvalidNode");
  
          NodeRef n1 = mlAwareNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
  
          NodeRef cat = mlAwareNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}cat"), ContentModel.TYPE_CATEGORY).getChildRef();
  
          // Add aspect
  
          mlAwareNodeService.addAspect(n1, categoryAspect, null);
          mlAwareNodeService.addAspect(n1, categoriesAspect, null);
          mlAwareNodeService.addAspect(n1, noderefAspect, null);
          mlAwareNodeService.addAspect(n1, noderefsAspect, null);
  
          assertNull(mlAwareNodeService.getProperty(n1, aspectCategoryProp));
          assertNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertNull(mlAwareNodeService.getProperty(n1, aspectNoderefProp));
          assertNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectCategoryProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp));
          assertNull(nodeService.getProperty(n1, aspectCategoryProp));
          assertNull(nodeService.getProperty(n1, aspectCategoriesProp));
          assertNull(nodeService.getProperty(n1, aspectNoderefProp));
          assertNull(nodeService.getProperty(n1, aspectNoderefsProp));
          assertNull(nodeService.getProperties(n1).get(aspectCategoryProp));
          assertNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertNull(nodeService.getProperties(n1).get(aspectNoderefProp));
          assertNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
  
          // Set null property
  
          mlAwareNodeService.setProperty(n1, aspectCategoryProp, null);
          mlAwareNodeService.setProperty(n1, aspectCategoriesProp, null);
          mlAwareNodeService.setProperty(n1, aspectNoderefProp, null);
          mlAwareNodeService.setProperty(n1, aspectNoderefsProp, null);
  
          assertNull(mlAwareNodeService.getProperty(n1, aspectCategoryProp));
          assertNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertNull(mlAwareNodeService.getProperty(n1, aspectNoderefProp));
          assertNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectCategoryProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp));
          assertNull(nodeService.getProperty(n1, aspectCategoryProp));
          assertNull(nodeService.getProperty(n1, aspectCategoriesProp));
          assertNull(nodeService.getProperty(n1, aspectNoderefProp));
          assertNull(nodeService.getProperty(n1, aspectNoderefsProp));
          assertNull(nodeService.getProperties(n1).get(aspectCategoryProp));
          assertNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertNull(nodeService.getProperties(n1).get(aspectNoderefProp));
          assertNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
  
          // Set invalid
  
          mlAwareNodeService.setProperty(n1, aspectCategoryProp, invalidNodeRef);
          mlAwareNodeService.setProperty(n1, aspectCategoriesProp, invalidNodeRef);
          mlAwareNodeService.setProperty(n1, aspectNoderefProp, invalidNodeRef);
          mlAwareNodeService.setProperty(n1, aspectNoderefsProp, invalidNodeRef);
  
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectCategoryProp));
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefProp));
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectCategoryProp));
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefProp));
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp)).size());
          assertNull(nodeService.getProperty(n1, aspectCategoryProp));
          assertNotNull(nodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(0, ((Collection) nodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertNull(nodeService.getProperty(n1, aspectNoderefProp));
          assertNotNull(nodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(0, ((Collection) nodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertNull(nodeService.getProperties(n1).get(aspectCategoryProp));
          assertNotNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(0, ((Collection) nodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertNull(nodeService.getProperties(n1).get(aspectNoderefProp));
          assertNotNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(0, ((Collection) nodeService.getProperties(n1).get(aspectNoderefsProp)).size());
  
          // Set valid node ref
  
          mlAwareNodeService.setProperty(n1, aspectCategoryProp, rootNodeRef);
          mlAwareNodeService.setProperty(n1, aspectCategoriesProp, rootNodeRef);
          mlAwareNodeService.setProperty(n1, aspectNoderefProp, rootNodeRef);
          mlAwareNodeService.setProperty(n1, aspectNoderefsProp, rootNodeRef);
  
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectCategoryProp));
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefProp));
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectCategoryProp));
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefProp));
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp)).size());
          assertNull(nodeService.getProperty(n1, aspectCategoryProp));
          assertNotNull(nodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(0, ((Collection) nodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertNotNull(nodeService.getProperty(n1, aspectNoderefProp));
          assertNotNull(nodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(1, ((Collection) nodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertTrue(((Collection) nodeService.getProperty(n1, aspectNoderefsProp)).iterator().next() instanceof NodeRef);
          assertNull(nodeService.getProperties(n1).get(aspectCategoryProp));
          assertNotNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(0, ((Collection) nodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertNotNull(nodeService.getProperties(n1).get(aspectNoderefProp));
          assertNotNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(1, ((Collection) nodeService.getProperties(n1).get(aspectNoderefsProp)).size());
          assertTrue(((Collection) nodeService.getProperties(n1).get(aspectNoderefsProp)).iterator().next() instanceof NodeRef);
  
          // Set valid cat
  
          mlAwareNodeService.setProperty(n1, aspectCategoryProp, cat.toString());
          mlAwareNodeService.setProperty(n1, aspectCategoriesProp, cat);
          mlAwareNodeService.setProperty(n1, aspectNoderefProp, cat);
          mlAwareNodeService.setProperty(n1, aspectNoderefsProp, cat);
  
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectCategoryProp));
          assertTrue(nodeService.getProperty(n1, aspectCategoryProp) instanceof NodeRef);
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefProp));
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectCategoryProp));
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefProp));
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp)).size());
          assertNotNull(nodeService.getProperty(n1, aspectCategoryProp));
          assertTrue(nodeService.getProperty(n1, aspectCategoryProp) instanceof NodeRef);
          assertNotNull(nodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(1, ((Collection) nodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertTrue(((Collection) nodeService.getProperty(n1, aspectCategoriesProp)).iterator().next() instanceof NodeRef);
          assertNotNull(nodeService.getProperty(n1, aspectNoderefProp));
          assertNotNull(nodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(1, ((Collection) nodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertTrue(((Collection) nodeService.getProperty(n1, aspectNoderefsProp)).iterator().next() instanceof NodeRef);
          assertNotNull(nodeService.getProperties(n1).get(aspectCategoryProp));
          assertNotNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(1, ((Collection) nodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertTrue(((Collection) nodeService.getProperties(n1).get(aspectCategoriesProp)).iterator().next() instanceof NodeRef);
          assertNotNull(nodeService.getProperties(n1).get(aspectNoderefProp));
          assertNotNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(1, ((Collection) nodeService.getProperties(n1).get(aspectNoderefsProp)).size());
          assertTrue(((Collection) nodeService.getProperties(n1).get(aspectNoderefsProp)).iterator().next() instanceof NodeRef);
  
          // Set empty list
  
          mlAwareNodeService.setProperty(n1, aspectCategoriesProp, new ArrayList<NodeRef>());
          mlAwareNodeService.setProperty(n1, aspectNoderefsProp, new ArrayList<NodeRef>());
  
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(0, ((Collection) mlAwareNodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(0, ((Collection) mlAwareNodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(0, ((Collection) mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(0, ((Collection) mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp)).size());
          assertNotNull(nodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(0, ((Collection) nodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertNotNull(nodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(0, ((Collection) nodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertNotNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(0, ((Collection) nodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertNotNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(0, ((Collection) nodeService.getProperties(n1).get(aspectNoderefsProp)).size());
  
          // Set invalid noderef in list
  
          ArrayList<NodeRef> cats = new ArrayList<NodeRef>();
          cats.add(invalidNodeRef);
          mlAwareNodeService.setProperty(n1, aspectCategoriesProp, cats);
          mlAwareNodeService.setProperty(n1, aspectNoderefsProp, cats);
  
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp)).size());
          assertNotNull(nodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(0, ((Collection) nodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertNotNull(nodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(0, ((Collection) nodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertNotNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(0, ((Collection) nodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertNotNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(0, ((Collection) nodeService.getProperties(n1).get(aspectNoderefsProp)).size());
  
          // Set valid ref in list
  
          cats = new ArrayList<NodeRef>();
          cats.add(rootNodeRef);
          mlAwareNodeService.setProperty(n1, aspectCategoriesProp, cats);
          mlAwareNodeService.setProperty(n1, aspectNoderefsProp, cats);
  
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp)).size());
          assertNotNull(nodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(0, ((Collection) nodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertNotNull(nodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(1, ((Collection) nodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertTrue(((Collection) nodeService.getProperty(n1, aspectNoderefsProp)).iterator().next() instanceof NodeRef);
          assertNotNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(0, ((Collection) nodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertNotNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(1, ((Collection) nodeService.getProperties(n1).get(aspectNoderefsProp)).size());
          assertTrue(((Collection) nodeService.getProperties(n1).get(aspectNoderefsProp)).iterator().next() instanceof NodeRef);
  
          // set valid cat in list
  
          cats = new ArrayList<NodeRef>();
          cats.add(cat);
          mlAwareNodeService.setProperty(n1, aspectCategoriesProp, cats);
          mlAwareNodeService.setProperty(n1, aspectNoderefsProp, cats);
  
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(1, ((Collection) mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp)).size());
          assertNotNull(nodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(1, ((Collection) nodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertTrue( ((Collection) nodeService.getProperty(n1, aspectCategoriesProp)).iterator().next() instanceof NodeRef);
          assertNotNull(nodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(1, ((Collection) nodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertTrue(((Collection) nodeService.getProperty(n1, aspectNoderefsProp)).iterator().next() instanceof NodeRef);
          assertNotNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(1, ((Collection) nodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertTrue(((Collection) nodeService.getProperties(n1).get(aspectCategoriesProp)).iterator().next() instanceof NodeRef);
          assertNotNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(1, ((Collection) nodeService.getProperties(n1).get(aspectNoderefsProp)).size());
          assertTrue(((Collection) nodeService.getProperties(n1).get(aspectNoderefsProp)).iterator().next() instanceof NodeRef);
  
          // Test list with invalid, noderef and cat
  
          cats = new ArrayList<NodeRef>();
          cats.add(rootNodeRef);
          cats.add(invalidNodeRef);
          cats.add(cat);
          mlAwareNodeService.setProperty(n1, aspectCategoriesProp, cats);
          mlAwareNodeService.setProperty(n1, aspectNoderefsProp, cats);
  
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(3, ((Collection) mlAwareNodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(3, ((Collection) mlAwareNodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(3, ((Collection) mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(3, ((Collection) mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp)).size());
          assertNotNull(nodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(1, ((Collection) nodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertNotNull(nodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(2, ((Collection) nodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertNotNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(1, ((Collection) nodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertNotNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(2, ((Collection) nodeService.getProperties(n1).get(aspectNoderefsProp)).size());
  
      }
  
      @Test
      public void testAddAspectNull()
      {
          NodeRef invalidNodeRef = new NodeRef(rootNodeRef.getStoreRef(), "InvalidNode");
  
          NodeRef n1 = mlAwareNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
  
          NodeRef cat = mlAwareNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}cat"), ContentModel.TYPE_CATEGORY).getChildRef();
  
          // Add aspect
  
          nodeService.addAspect(n1, categoryAspect, null);
          nodeService.addAspect(n1, categoriesAspect, null);
          nodeService.addAspect(n1, noderefAspect, null);
          nodeService.addAspect(n1, noderefsAspect, null);
  
          assertNull(mlAwareNodeService.getProperty(n1, aspectCategoryProp));
          assertNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertNull(mlAwareNodeService.getProperty(n1, aspectNoderefProp));
          assertNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectCategoryProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp));
          assertNull(nodeService.getProperty(n1, aspectCategoryProp));
          assertNull(nodeService.getProperty(n1, aspectCategoriesProp));
          assertNull(nodeService.getProperty(n1, aspectNoderefProp));
          assertNull(nodeService.getProperty(n1, aspectNoderefsProp));
          assertNull(nodeService.getProperties(n1).get(aspectCategoryProp));
          assertNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertNull(nodeService.getProperties(n1).get(aspectNoderefProp));
          assertNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
      }
  
      @Test
      public void testAddAspectNullValues()
      {
          NodeRef invalidNodeRef = new NodeRef(rootNodeRef.getStoreRef(), "InvalidNode");
  
          NodeRef n1 = mlAwareNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
  
          NodeRef cat = mlAwareNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}cat"), ContentModel.TYPE_CATEGORY).getChildRef();
  
          HashMap<QName, Serializable> properties1 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties2 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties3 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties4 = new HashMap<QName, Serializable>();
          properties1.put(aspectCategoryProp, null);
          properties2.put(aspectCategoriesProp, null);
          properties3.put(aspectNoderefProp, null);
          properties4.put(aspectNoderefsProp, null);
  
          // Add aspect
  
          nodeService.addAspect(n1, categoryAspect, properties1);
          nodeService.addAspect(n1, categoriesAspect, properties2);
          nodeService.addAspect(n1, noderefAspect, properties3);
          nodeService.addAspect(n1, noderefsAspect, properties4);
  
          assertNull(mlAwareNodeService.getProperty(n1, aspectCategoryProp));
          assertNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertNull(mlAwareNodeService.getProperty(n1, aspectNoderefProp));
          assertNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectCategoryProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp));
          assertNull(nodeService.getProperty(n1, aspectCategoryProp));
          assertNull(nodeService.getProperty(n1, aspectCategoriesProp));
          assertNull(nodeService.getProperty(n1, aspectNoderefProp));
          assertNull(nodeService.getProperty(n1, aspectNoderefsProp));
          assertNull(nodeService.getProperties(n1).get(aspectCategoryProp));
          assertNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertNull(nodeService.getProperties(n1).get(aspectNoderefProp));
          assertNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
      }
  
      @Test
      public void testAddAspectInvalidValues()
      {
          NodeRef invalidNodeRef = new NodeRef(rootNodeRef.getStoreRef(), "InvalidNode");
          NodeRef testInvalid = invalidNodeRef;
  
          NodeRef n1 = mlAwareNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
  
          NodeRef cat = mlAwareNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}cat"), ContentModel.TYPE_CATEGORY).getChildRef();
  
          HashMap<QName, Serializable> properties1 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties2 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties3 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties4 = new HashMap<QName, Serializable>();
          properties1.put(aspectCategoryProp, invalidNodeRef);
          properties2.put(aspectCategoriesProp, invalidNodeRef);
          properties3.put(aspectNoderefProp, invalidNodeRef);
          properties4.put(aspectNoderefsProp, invalidNodeRef);
          
          assertEquals(testInvalid, invalidNodeRef);
  
          // Add aspect
  
          nodeService.addAspect(n1, categoryAspect, properties1);
          nodeService.addAspect(n1, categoriesAspect, properties2);
          nodeService.addAspect(n1, noderefAspect, properties3);
          nodeService.addAspect(n1, noderefsAspect, properties4);
  
          assertNull(mlAwareNodeService.getProperty(n1, aspectCategoryProp));
          assertNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertNull(mlAwareNodeService.getProperty(n1, aspectNoderefProp));
          assertNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectCategoryProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp));
          assertNull(nodeService.getProperty(n1, aspectCategoryProp));
          assertNull(nodeService.getProperty(n1, aspectCategoriesProp));
          assertNull(nodeService.getProperty(n1, aspectNoderefProp));
          assertNull(nodeService.getProperty(n1, aspectNoderefsProp));
          assertNull(nodeService.getProperties(n1).get(aspectCategoryProp));
          assertNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertNull(nodeService.getProperties(n1).get(aspectNoderefProp));
          assertNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
      }
  
      @Test
      public void testAddAspectValidNode()
      {
          NodeRef invalidNodeRef = new NodeRef(rootNodeRef.getStoreRef(), "InvalidNode");
  
          NodeRef n1 = mlAwareNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
  
          NodeRef cat = mlAwareNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}cat"), ContentModel.TYPE_CATEGORY).getChildRef();
  
          HashMap<QName, Serializable> properties1 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties2 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties3 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties4 = new HashMap<QName, Serializable>();
          properties1.put(aspectCategoryProp, rootNodeRef);
          properties2.put(aspectCategoriesProp, rootNodeRef);
          properties3.put(aspectNoderefProp, rootNodeRef);
          properties4.put(aspectNoderefsProp, rootNodeRef);
  
          // Add aspect
  
          nodeService.addAspect(n1, categoryAspect, properties1);
          nodeService.addAspect(n1, categoriesAspect, properties2);
          nodeService.addAspect(n1, noderefAspect, properties3);
          nodeService.addAspect(n1, noderefsAspect, properties4);
  
          assertNull(mlAwareNodeService.getProperty(n1, aspectCategoryProp));
          assertNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefProp));
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectCategoryProp));
          assertNull(mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp));
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefProp));
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp));
          assertNull(nodeService.getProperty(n1, aspectCategoryProp));
          assertNull(nodeService.getProperty(n1, aspectCategoriesProp));
          assertNotNull(nodeService.getProperty(n1, aspectNoderefProp));
          assertNotNull(nodeService.getProperty(n1, aspectNoderefsProp));
          assertNull(nodeService.getProperties(n1).get(aspectCategoryProp));
          assertNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertNotNull(nodeService.getProperties(n1).get(aspectNoderefProp));
          assertNotNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
      }
  
      @Test
      public void testAddAspectValidCategory()
      {
          NodeRef invalidNodeRef = new NodeRef(rootNodeRef.getStoreRef(), "InvalidNode");
  
          NodeRef n1 = mlAwareNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
  
          NodeRef cat = mlAwareNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}cat"), ContentModel.TYPE_CATEGORY).getChildRef();
  
          HashMap<QName, Serializable> properties1 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties2 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties3 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties4 = new HashMap<QName, Serializable>();
          properties1.put(aspectCategoryProp, cat);
          properties2.put(aspectCategoriesProp, cat);
          properties3.put(aspectNoderefProp, cat);
          properties4.put(aspectNoderefsProp, cat);
  
          // Add aspect
  
          nodeService.addAspect(n1, categoryAspect, properties1);
          nodeService.addAspect(n1, categoriesAspect, properties2);
          nodeService.addAspect(n1, noderefAspect, properties3);
          nodeService.addAspect(n1, noderefsAspect, properties4);
  
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectCategoryProp));
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefProp));
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectCategoryProp));
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectCategoriesProp));
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefProp));
          assertNotNull(mlAwareNodeService.getProperties(n1).get(aspectNoderefsProp));
          assertNotNull(nodeService.getProperty(n1, aspectCategoryProp));
          assertNotNull(nodeService.getProperty(n1, aspectCategoriesProp));
          assertNotNull(nodeService.getProperty(n1, aspectNoderefProp));
          assertNotNull(nodeService.getProperty(n1, aspectNoderefsProp));
          assertNotNull(nodeService.getProperties(n1).get(aspectCategoryProp));
          assertNotNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertNotNull(nodeService.getProperties(n1).get(aspectNoderefProp));
          assertNotNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
      }
  
      @Test
      public void testAddAspectEmptyList()
      {
          NodeRef invalidNodeRef = new NodeRef(rootNodeRef.getStoreRef(), "InvalidNode");
  
          NodeRef n1 = mlAwareNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
  
          NodeRef cat = mlAwareNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}cat"), ContentModel.TYPE_CATEGORY).getChildRef();
  
          HashMap<QName, Serializable> properties1 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties2 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties3 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties4 = new HashMap<QName, Serializable>();
          ArrayList<NodeRef> vals = new ArrayList<NodeRef>();
          properties2.put(aspectCategoriesProp, vals);
          properties4.put(aspectNoderefsProp, vals);
  
          // Add aspect
  
          nodeService.addAspect(n1, categoryAspect, properties1);
          nodeService.addAspect(n1, categoriesAspect, properties2);
          nodeService.addAspect(n1, noderefAspect, properties3);
          nodeService.addAspect(n1, noderefsAspect, properties4);
  
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(0, ((Collection) mlAwareNodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(0, ((Collection) mlAwareNodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectCategoriesProp));
          assertEquals(0, ((Collection) mlAwareNodeService.getProperty(n1, aspectCategoriesProp)).size());
          assertNotNull(mlAwareNodeService.getProperty(n1, aspectNoderefsProp));
          assertEquals(0, ((Collection) mlAwareNodeService.getProperty(n1, aspectNoderefsProp)).size());
          assertNotNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(0, ((Collection) nodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertNotNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(0, ((Collection) nodeService.getProperties(n1).get(aspectNoderefsProp)).size());
          assertNotNull(nodeService.getProperties(n1).get(aspectCategoriesProp));
          assertEquals(0, ((Collection) nodeService.getProperties(n1).get(aspectCategoriesProp)).size());
          assertNotNull(nodeService.getProperties(n1).get(aspectNoderefsProp));
          assertEquals(0, ((Collection) nodeService.getProperties(n1).get(aspectNoderefsProp)).size());
      }
  
      @Test
      public void testAddAspectInvalidList()
      {
          NodeRef invalidNodeRef = new NodeRef(rootNodeRef.getStoreRef(), "InvalidNode");
  
          NodeRef n1 = mlAwareNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
  
          NodeRef cat = mlAwareNodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}cat"), ContentModel.TYPE_CATEGORY).getChildRef();
  
          HashMap<QName, Serializable> properties1 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties2 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties3 = new HashMap<QName, Serializable>();
          HashMap<QName, Serializable> properties4 = new HashMap<QName, Serializable>();
          ArrayList<NodeRef> vals = new ArrayList<NodeRef>();
          vals.add(invalidNodeRef);
          properties2.put(aspectCategoriesProp, vals);
          properties4.put(aspectNoderefsProp, vals);
  
          // Add aspect
  
          nodeService.addAspect(n1, categoryAspect, properties1);
          nodeService.addAspect(n1, categoriesAspect, properties2);
  