blob: 19d7d02d6740d4b2091415986517841f796aaead [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2016 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.orcs.api;
import static org.eclipse.osee.framework.core.enums.SystemUser.OseeSystem;
import org.eclipse.osee.framework.core.data.TupleTypeId;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.jdbc.JdbcException;
import org.eclipse.osee.orcs.KeyValueOps;
import org.eclipse.osee.orcs.OrcsApi;
import org.eclipse.osee.orcs.db.mock.OrcsIntegrationByClassRule;
import org.eclipse.osee.orcs.db.mock.OseeClassDatabase;
import org.eclipse.osee.orcs.db.mock.OsgiService;
import org.eclipse.osee.orcs.transaction.TransactionBuilder;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TestRule;
/**
* @author Angel Avila
*/
public class OrcsTupleTest {
@Rule
public TestRule db = OrcsIntegrationByClassRule.integrationRule(this);
@Rule
public final ExpectedException exception = ExpectedException.none();
@OsgiService
private OrcsApi orcsApi;
private KeyValueOps keyValueOps;
@Before
public void setUp() throws Exception {
keyValueOps = orcsApi.getKeyValueOps();
}
@AfterClass
public static void cleanup() throws Exception {
OseeClassDatabase.cleanup();
}
@Test
public void testPutIfAbsent() throws OseeCoreException {
String newValue = "hello";
Long key = keyValueOps.putIfAbsent(newValue);
Assert.assertTrue(key > 0L);
Long keyAttempt2 = keyValueOps.putIfAbsent(newValue);
Assert.assertEquals(key, keyAttempt2);
}
@Test(expected = JdbcException.class)
public void testAddTuple2() throws OseeCoreException {
TupleTypeId createTuple2Type = TupleTypeId.valueOf(24L);
TransactionBuilder transaction =
orcsApi.getTransactionFactory().createTransaction(CoreBranches.COMMON_ID, OseeSystem, "Add Tuple2 Test");
Long gamma_id = transaction.addTuple(createTuple2Type, 234L, "t");
transaction.commit();
Assert.assertTrue(gamma_id > 0L);
gamma_id = transaction.addTuple(createTuple2Type, 234L, "t");
transaction.commit();
}
@Test(expected = JdbcException.class)
public void testAddTuple3() throws OseeCoreException {
TupleTypeId createTuple3Type = TupleTypeId.valueOf(44L);
TransactionBuilder transaction =
orcsApi.getTransactionFactory().createTransaction(CoreBranches.COMMON_ID, OseeSystem, "Add Tuple3 Test");
Long gamma_id = transaction.addTuple(createTuple3Type, 244L, 12L, "three");
transaction.commit();
Assert.assertTrue(gamma_id > 0L);
gamma_id = transaction.addTuple(createTuple3Type, 244L, 12L, "three");
transaction.commit();
}
@Test(expected = JdbcException.class)
public void testAddTuple4() throws OseeCoreException {
TupleTypeId createTuple4Type = TupleTypeId.valueOf(44L);
TransactionBuilder transaction =
orcsApi.getTransactionFactory().createTransaction(CoreBranches.COMMON_ID, OseeSystem, "Add Tuple4 Test");
Long gamma_id = transaction.addTuple(createTuple4Type, 244L, 12L, "four", "four2");
transaction.commit();
Assert.assertTrue(gamma_id > 0L);
gamma_id = transaction.addTuple(createTuple4Type, 244L, 12L, "four", "four2");
transaction.commit();
}
}