128N/A/*
128N/A * CDDL HEADER START
128N/A *
128N/A * The contents of this file are subject to the terms of the
128N/A * Common Development and Distribution License, Version 1.0 only
128N/A * (the "License"). You may not use this file except in compliance
128N/A * with the License.
128N/A *
128N/A * You can obtain a copy of the license at
128N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
128N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
128N/A * See the License for the specific language governing permissions
128N/A * and limitations under the License.
128N/A *
128N/A * When distributing Covered Code, include this CDDL HEADER in each
128N/A * file and include the License file at
128N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
128N/A * add the following below this CDDL HEADER, with the fields enclosed
873N/A * by brackets "[]" replaced with your own identifying information:
128N/A * Portions Copyright [yyyy] [name of copyright owner]
128N/A *
128N/A * CDDL HEADER END
128N/A *
128N/A *
5205N/A * Copyright 2006-2010 Sun Microsystems, Inc.
128N/A */
1182N/Apackage org.opends.server.replication.plugin;
128N/A
128N/Aimport org.opends.server.core.DirectoryServer;
1183N/Aimport org.opends.server.replication.ReplicationTestCase;
1182N/Aimport org.opends.server.replication.common.ChangeNumber;
5205N/Aimport org.opends.server.replication.plugin.AttrValueHistorical;
128N/Aimport org.opends.server.types.AttributeType;
128N/Aimport org.opends.server.types.AttributeValue;
4134N/Aimport org.opends.server.types.AttributeValues;
128N/Aimport org.opends.server.util.TimeThread;
128N/Aimport org.testng.annotations.DataProvider;
128N/Aimport org.testng.annotations.Test;
128N/Aimport static org.testng.Assert.*;
128N/A
128N/A
128N/A/**
128N/A * Test of ValueInfo
128N/A */
1183N/Apublic class ValueInfoTest extends ReplicationTestCase
128N/A{
128N/A /**
128N/A * Build some data for the ValueInfo test below.
128N/A */
128N/A @DataProvider(name = "valueInfo")
128N/A public Object[][] createData() {
128N/A AttributeType type = DirectoryServer.getAttributeType("description");
128N/A
4134N/A AttributeValue att1 = AttributeValues.create(type, "string");
4134N/A AttributeValue att2 = AttributeValues.create(type, "value");
4134N/A AttributeValue att3 = AttributeValues.create(type, "again");
128N/A
4802N/A ChangeNumber del1 = new ChangeNumber(1, 0, 1);
4802N/A ChangeNumber del2 = new ChangeNumber(1, 1, 1);
4802N/A ChangeNumber del3 = new ChangeNumber(1, 0, 2);
128N/A
4802N/A ChangeNumber upd1 = new ChangeNumber(TimeThread.getTime(), 123, 45);
4802N/A ChangeNumber upd2 = new ChangeNumber(TimeThread.getTime()+ 1000, 123, 45);
4802N/A ChangeNumber upd3 = new ChangeNumber(TimeThread.getTime(), 321, 54);
128N/A
128N/A return new Object[][] {
128N/A {att1,null,null},
128N/A {att1,upd1,del1},
128N/A {att2,upd2,del2},
128N/A {att3,upd3,del3}};
128N/A }
128N/A
128N/A /**
128N/A * Create a ValueInfo and check the methods
128N/A */
128N/A @Test(dataProvider = "valueInfo")
128N/A public void valueInfo(AttributeValue value,
128N/A ChangeNumber CNupdate,
128N/A ChangeNumber CNdelete)
128N/A throws Exception
128N/A {
510N/A AttributeType type = DirectoryServer.getAttributeType("description");
5205N/A AttrValueHistorical valInfo1 = new AttrValueHistorical(value,CNupdate,CNdelete);
5205N/A AttrValueHistorical valInfo2 = new AttrValueHistorical(value,CNupdate,CNupdate);
5205N/A AttrValueHistorical valInfo3 = new AttrValueHistorical(AttributeValues.create(type,"Test"),
128N/A CNupdate,CNupdate);
128N/A
128N/A // Check equals
128N/A assertFalse(valInfo1.equals(new Object())) ;
128N/A assertTrue(valInfo1.equals(valInfo1)) ;
128N/A assertTrue(valInfo1.equals(valInfo2)) ;
128N/A assertFalse(valInfo1.equals(valInfo3)) ;
128N/A
128N/A // Check hashcode
128N/A assertTrue(valInfo1.hashCode() == valInfo2.hashCode()) ;
128N/A
128N/A // Check getValueDeleteTime
128N/A if (valInfo1.getValueDeleteTime() != null)
128N/A {
128N/A assertTrue(valInfo1.getValueDeleteTime().compareTo(CNdelete) == 0);
128N/A }
128N/A
128N/A // Check getValueUpdateTime
128N/A if (valInfo1.getValueUpdateTime() != null)
128N/A {
128N/A assertTrue(valInfo1.getValueUpdateTime().compareTo(CNupdate) == 0);
128N/A }
128N/A
128N/A // Check getValue
5205N/A assertTrue(valInfo1.getAttributeValue().equals(value)) ;
128N/A
128N/A // Chek valueUpdateTime
128N/A if (CNupdate == null)
128N/A {
128N/A assertFalse(valInfo1.isUpdate());
128N/A }
128N/A else
128N/A {
128N/A assertTrue(valInfo1.isUpdate());
128N/A }
128N/A }
128N/A}