/* * * Copyright (c) 2010 ForgeRock Inc. All Rights Reserved * * The contents of this file are subject to the terms * of the Common Development and Distribution License * (the License). You may not use this file except in * compliance with the License. * * You can obtain a copy of the License at * http://www.opensource.org/licenses/cddl1.php or * OpenIDM/legal/CDDLv1.0.txt * See the License for the specific language governing * permission and limitations under the License. * * When distributing Covered Code, include this CDDL * Header Notice in each file and include the License file * at OpenIDM/legal/CDDLv1.0.txt. * If applicable, add the following below the CDDL Header, * with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted 2010 [name of copyright owner]" * * Portions Copyrighted 2011 Viliam Repan (lazyman) * * $Id$ */ package com.evolveum.polygon.csvfile; import org.identityconnectors.common.logging.Log; import org.identityconnectors.framework.common.exceptions.ConnectorException; import org.identityconnectors.framework.common.exceptions.UnknownUidException; import org.identityconnectors.framework.common.objects.*; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import com.evolveum.polygon.csvfile.CSVFileConfiguration; import com.evolveum.polygon.csvfile.CSVFileConnector; import com.evolveum.polygon.csvfile.util.TestUtils; import com.evolveum.polygon.csvfile.util.Utils; import java.io.File; import java.lang.reflect.Method; import java.util.HashSet; import java.util.Set; import static org.testng.Assert.*; /** * @author Viliam Repan (lazyman) */ public class UpdateOpTest extends AbstractCsvTest { private static final Log LOG = Log.getLog(UpdateOpTest.class); private CSVFileConnector connector; public UpdateOpTest() { super(LOG); } @Override public void customBeforeMethod(Method method) throws Exception { File file = TestUtils.getTestFile("update.csv"); File backup = TestUtils.getTestFile("update-backup.csv"); Utils.copyAndReplace(backup, file); CSVFileConfiguration config = new CSVFileConfiguration(); config.setFilePath(TestUtils.getTestFile("update.csv")); config.setUniqueAttribute("uid"); config.setPasswordAttribute("password"); connector = new CSVFileConnector(); connector.init(config); } @Override public void customAfterMethod(Method method) throws Exception { connector.dispose(); connector = null; } @Override public void customAfterClass() throws Exception { File file = TestUtils.getTestFile("update.csv"); file.delete(); } @Test(expectedExceptions = IllegalArgumentException.class) public void nullObjectClass() { connector.update(null, new Uid("vilo"), new HashSet<Attribute>(), null); } @Test(expectedExceptions = ConnectorException.class) public void badObjectClass() { connector.update(ObjectClass.GROUP, new Uid("vilo"), new HashSet<Attribute>(), null); } @Test(expectedExceptions = IllegalArgumentException.class) public void nullUid() { connector.update(ObjectClass.ACCOUNT, null, new HashSet<Attribute>(), null); } @Test(expectedExceptions = UnknownUidException.class) public void notExistingUid() { connector.update(ObjectClass.ACCOUNT, new Uid("unknown"), new HashSet<Attribute>(), null); } @Test(expectedExceptions = IllegalArgumentException.class) public void nullAttributeSet() { connector.update(ObjectClass.ACCOUNT, new Uid("vilo"), null, null); } @Test public void updateNonExistingAttribute() throws Exception { Set<Attribute> attributes = new HashSet<Attribute>(); attributes.add(AttributeBuilder.build("nonExisting", "repantest")); Uid uid = connector.update(ObjectClass.ACCOUNT, new Uid("vilo"), attributes, null); assertNotNull(uid); assertEquals("vilo", uid.getUidValue()); String result = TestUtils.compareFiles(TestUtils.getTestFile("update.csv"), TestUtils.getTestFile("update-result-non-existing.csv")); assertNull(result, "File updated incorrectly: " + result); } @Test public void updateAttributeDelete() throws Exception { Set<Attribute> attributes = new HashSet<Attribute>(); attributes.add(AttributeBuilder.build("lastName")); Uid uid = connector.update(ObjectClass.ACCOUNT, new Uid("vilo"), attributes, null); assertNotNull(uid); assertEquals("vilo", uid.getUidValue()); String result = TestUtils.compareFiles(TestUtils.getTestFile("update.csv"), TestUtils.getTestFile("update-result-delete.csv")); assertNull(result, "File updated incorrectly: " + result); } @Test public void updateAttributeAdd() throws Exception { Set<Attribute> attributes = new HashSet<Attribute>(); attributes.add(AttributeBuilder.build("lastName", "repantest")); Uid uid = connector.update(ObjectClass.ACCOUNT, new Uid("vilo"), attributes, null); assertNotNull(uid); assertEquals("vilo", uid.getUidValue()); String result = TestUtils.compareFiles(TestUtils.getTestFile("update.csv"), TestUtils.getTestFile("update-result-add.csv")); assertNull(result, "File updated incorrectly: " + result); } @Test public void renameWhenUniqueEqualsNamingAttribute() throws Exception { Set<Attribute> attributes = new HashSet<Attribute>(); attributes.add(new Name("troll")); Uid uid = connector.update(ObjectClass.ACCOUNT, new Uid("vilo"), attributes, null); assertNotNull(uid); assertEquals(uid.getUidValue(), "troll"); String result = TestUtils.compareFiles(TestUtils.getTestFile("update.csv"), TestUtils.getTestFile("update-result-rename.csv")); assertNull(result, "File updated incorrectly: " + result); } }