From 467849887d177c4cd7a543a8596e39abc6bdfe39 Mon Sep 17 00:00:00 2001 From: donald.g.dunne Date: Thu, 16 Jul 2015 16:36:30 -0700 Subject: feature[ats_ATS186279]: Performance Report - Add country, prog, insert and activity columns Change-Id: If891236c778971295866259607fdcbe517e4d577 --- .../eclipse/osee/ats/core/AllAtsCoreTestSuite.java | 4 +- .../ats/core/column/AtsCore_Column_JT_Suite.java | 4 + .../osee/ats/core/column/CountryColumnTest.java | 67 +++++++ .../core/column/InsertionActivityColumnTest.java | 70 +++++++ .../osee/ats/core/column/InsertionColumnTest.java | 67 +++++++ .../osee/ats/core/column/ProgramColumnTest.java | 67 +++++++ .../ats/core/config/AtsCore_Config_JT_Suite.java | 37 ++++ .../ats/core/config/WorkPackageUtilityTest.java | 203 +++++++++++++++++++++ 8 files changed, 518 insertions(+), 1 deletion(-) create mode 100644 plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/CountryColumnTest.java create mode 100644 plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/InsertionActivityColumnTest.java create mode 100644 plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/InsertionColumnTest.java create mode 100644 plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/ProgramColumnTest.java create mode 100644 plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/config/AtsCore_Config_JT_Suite.java create mode 100644 plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/config/WorkPackageUtilityTest.java (limited to 'plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core') diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AllAtsCoreTestSuite.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AllAtsCoreTestSuite.java index 5cb73d03641..334cbb9399f 100644 --- a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AllAtsCoreTestSuite.java +++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AllAtsCoreTestSuite.java @@ -12,6 +12,7 @@ package org.eclipse.osee.ats.core; import org.eclipse.osee.ats.core.ai.AtsCore_AI_Suite; import org.eclipse.osee.ats.core.column.AtsCore_Column_JT_Suite; +import org.eclipse.osee.ats.core.config.AtsCore_Config_JT_Suite; import org.eclipse.osee.ats.core.internal.column.ev.AtsCore_InternalColumnEv_JT_Suite; import org.eclipse.osee.ats.core.internal.log.AtsTest_Internal_Log_Suite; import org.eclipse.osee.ats.core.internal.state.AtsCore_Internal_State_Suite; @@ -31,6 +32,7 @@ import org.junit.runners.Suite; @Suite.SuiteClasses({ AtsCore_AI_Suite.class, AtsCore_Column_JT_Suite.class, + AtsCore_Config_JT_Suite.class, AtsTest_Internal_Log_Suite.class, AtsCore_Internal_State_Suite.class, AtsCore_Internal_Util_Suite.class, @@ -45,7 +47,7 @@ import org.junit.runners.Suite; AtsCore_Workflow_JT_Suite.class}) /** * This test suite contains tests that can be run as stand-alone JUnit tests (JT) - * + * * @author Donald G. Dunne */ public class AllAtsCoreTestSuite { diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/AtsCore_Column_JT_Suite.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/AtsCore_Column_JT_Suite.java index d87a39f9b6f..8ffcff553a6 100644 --- a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/AtsCore_Column_JT_Suite.java +++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/AtsCore_Column_JT_Suite.java @@ -21,8 +21,12 @@ import org.junit.runners.Suite; @Suite.SuiteClasses({ ActionableItemsColumnTest.class, AssigneeColumnTest.class, + CountryColumnTest.class, ImplementersColumnTest.class, + InsertionColumnTest.class, + InsertionActivityColumnTest.class, ParentTopTeamColumnTest.class, + ProgramColumnTest.class, TeamColumnUtilityTest.class}) /** * This test suite contains tests that can be run as stand-alone JUnit tests (JT) diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/CountryColumnTest.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/CountryColumnTest.java new file mode 100644 index 00000000000..b61ddf0c88a --- /dev/null +++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/CountryColumnTest.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2015 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.ats.core.column; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import org.eclipse.osee.ats.api.IAtsObject; +import org.eclipse.osee.ats.api.IAtsServices; +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.country.IAtsCountry; +import org.eclipse.osee.ats.core.config.WorkPackageUtility; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.Pair; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * Test case for {@link CountryColumn} + * + * @author Donald G. Dunne + */ +public class CountryColumnTest extends CountryColumn { + + // @formatter:off + @Mock private WorkPackageUtility util; + @Mock private IAtsServices services; + @Mock private IAtsWorkItem workItem; + @Mock private IAtsObject object; + @Mock private IAtsCountry country; + // @formatter:on + + @Before + public void setup() throws OseeCoreException { + MockitoAnnotations.initMocks(this); + } + + @Test + public void test() { + String str = CountryColumn.getCountryStr(object, services, util); + assertEquals(str, ""); + + when(util.getCountry(services, workItem)).thenReturn(new Pair(null, false)); + + str = CountryColumn.getCountryStr(workItem, services, util); + assertEquals(str, ""); + + when(util.getCountry(services, workItem)).thenReturn(new Pair(country, false)); + when(country.getName()).thenReturn("Country"); + str = CountryColumn.getCountryStr(workItem, services, util); + assertEquals(str, "Country"); + + when(util.getCountry(services, workItem)).thenReturn(new Pair(country, true)); + str = CountryColumn.getCountryStr(workItem, services, util); + assertEquals(str, "Country (I)"); + + } +} diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/InsertionActivityColumnTest.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/InsertionActivityColumnTest.java new file mode 100644 index 00000000000..70604be4815 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/InsertionActivityColumnTest.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2015 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.ats.core.column; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import org.eclipse.osee.ats.api.IAtsObject; +import org.eclipse.osee.ats.api.IAtsServices; +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.insertion.IAtsInsertionActivity; +import org.eclipse.osee.ats.core.config.WorkPackageUtility; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.Pair; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * Test case for {@link InsertionColumn} + * + * @author Donald G. Dunne + */ +public class InsertionActivityColumnTest extends InsertionColumn { + +// @formatter:off + @Mock private WorkPackageUtility util; + @Mock private IAtsServices services; + @Mock private IAtsWorkItem workItem; + @Mock private IAtsObject object; + @Mock private IAtsInsertionActivity program; + // @formatter:on + + @Before + public void setup() throws OseeCoreException { + MockitoAnnotations.initMocks(this); + } + + @Test + public void test() { + String str = InsertionActivityColumn.getInsertionActivityStr(object, services, util); + assertEquals(str, ""); + + when(util.getInsertionActivity(services, workItem)).thenReturn( + new Pair(null, false)); + + str = InsertionActivityColumn.getInsertionActivityStr(workItem, services, util); + assertEquals(str, ""); + + when(util.getInsertionActivity(services, workItem)).thenReturn( + new Pair(program, false)); + when(program.getName()).thenReturn("Country"); + str = InsertionActivityColumn.getInsertionActivityStr(workItem, services, util); + assertEquals(str, "Country"); + + when(util.getInsertionActivity(services, workItem)).thenReturn( + new Pair(program, true)); + str = InsertionActivityColumn.getInsertionActivityStr(workItem, services, util); + assertEquals(str, "Country (I)"); + + } +} diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/InsertionColumnTest.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/InsertionColumnTest.java new file mode 100644 index 00000000000..cc54a0a6982 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/InsertionColumnTest.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2015 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.ats.core.column; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import org.eclipse.osee.ats.api.IAtsObject; +import org.eclipse.osee.ats.api.IAtsServices; +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.insertion.IAtsInsertion; +import org.eclipse.osee.ats.core.config.WorkPackageUtility; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.Pair; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * Test case for {@link InsertionColumn} + * + * @author Donald G. Dunne + */ +public class InsertionColumnTest extends InsertionColumn { + + // @formatter:off + @Mock private WorkPackageUtility util; + @Mock private IAtsServices services; + @Mock private IAtsWorkItem workItem; + @Mock private IAtsObject object; + @Mock private IAtsInsertion program; + // @formatter:on + + @Before + public void setup() throws OseeCoreException { + MockitoAnnotations.initMocks(this); + } + + @Test + public void test() { + String str = InsertionColumn.getInsertionStr(object, services, util); + assertEquals(str, ""); + + when(util.getInsertion(services, workItem)).thenReturn(new Pair(null, false)); + + str = InsertionColumn.getInsertionStr(workItem, services, util); + assertEquals(str, ""); + + when(util.getInsertion(services, workItem)).thenReturn(new Pair(program, false)); + when(program.getName()).thenReturn("Country"); + str = InsertionColumn.getInsertionStr(workItem, services, util); + assertEquals(str, "Country"); + + when(util.getInsertion(services, workItem)).thenReturn(new Pair(program, true)); + str = InsertionColumn.getInsertionStr(workItem, services, util); + assertEquals(str, "Country (I)"); + + } +} diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/ProgramColumnTest.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/ProgramColumnTest.java new file mode 100644 index 00000000000..01c97d0980d --- /dev/null +++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/column/ProgramColumnTest.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2015 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.ats.core.column; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import org.eclipse.osee.ats.api.IAtsObject; +import org.eclipse.osee.ats.api.IAtsServices; +import org.eclipse.osee.ats.api.IAtsWorkItem; +import org.eclipse.osee.ats.api.program.IAtsProgram; +import org.eclipse.osee.ats.core.config.WorkPackageUtility; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.Pair; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * Test case for {@link ProgramColumn} + * + * @author Donald G. Dunne + */ +public class ProgramColumnTest extends ProgramColumn { + + // @formatter:off + @Mock private WorkPackageUtility util; + @Mock private IAtsServices services; + @Mock private IAtsWorkItem workItem; + @Mock private IAtsObject object; + @Mock private IAtsProgram program; + // @formatter:on + + @Before + public void setup() throws OseeCoreException { + MockitoAnnotations.initMocks(this); + } + + @Test + public void test() { + String str = ProgramColumn.getProgramStr(object, services, util); + assertEquals(str, ""); + + when(util.getProgram(services, workItem)).thenReturn(new Pair(null, false)); + + str = ProgramColumn.getProgramStr(workItem, services, util); + assertEquals(str, ""); + + when(util.getProgram(services, workItem)).thenReturn(new Pair(program, false)); + when(program.getName()).thenReturn("Country"); + str = ProgramColumn.getProgramStr(workItem, services, util); + assertEquals(str, "Country"); + + when(util.getProgram(services, workItem)).thenReturn(new Pair(program, true)); + str = ProgramColumn.getProgramStr(workItem, services, util); + assertEquals(str, "Country (I)"); + + } +} diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/config/AtsCore_Config_JT_Suite.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/config/AtsCore_Config_JT_Suite.java new file mode 100644 index 00000000000..fc99b1ccb96 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/config/AtsCore_Config_JT_Suite.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2015 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.ats.core.config; + +import org.eclipse.osee.framework.jdk.core.util.OseeProperties; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({WorkPackageUtilityTest.class}) +/** + * This test suite contains tests that can be run as stand-alone JUnit tests (JT) + * + * @author Donald G. Dunne + */ +public class AtsCore_Config_JT_Suite { + @BeforeClass + public static void setUp() throws Exception { + OseeProperties.setIsInTest(true); + System.out.println("\n\nBegin " + AtsCore_Config_JT_Suite.class.getSimpleName()); + } + + @AfterClass + public static void tearDown() throws Exception { + System.out.println("End " + AtsCore_Config_JT_Suite.class.getSimpleName()); + } +} diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/config/WorkPackageUtilityTest.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/config/WorkPackageUtilityTest.java new file mode 100644 index 00000000000..2fb5a94a603 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/config/WorkPackageUtilityTest.java @@ -0,0 +1,203 @@ +/******************************************************************************* + * Copyright (c) 2015 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.ats.core.config; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.when; +import org.eclipse.osee.ats.api.IAtsServices; +import org.eclipse.osee.ats.api.country.IAtsCountry; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.data.AtsRelationTypes; +import org.eclipse.osee.ats.api.insertion.IAtsInsertion; +import org.eclipse.osee.ats.api.insertion.IAtsInsertionActivity; +import org.eclipse.osee.ats.api.program.IAtsProgram; +import org.eclipse.osee.ats.api.team.IAtsConfigItemFactory; +import org.eclipse.osee.ats.api.workdef.IAttributeResolver; +import org.eclipse.osee.ats.api.workdef.IRelationResolver; +import org.eclipse.osee.ats.api.workflow.IAtsGoal; +import org.eclipse.osee.ats.api.workflow.IAtsTask; +import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.framework.jdk.core.type.Pair; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * Test Case for {@link WorkPackageUtility} + * + * @author Donald G. Dunne + */ +public class WorkPackageUtilityTest { + + // @formatter:off + @Mock private IAtsGoal goal; + @Mock private IAtsTeamWorkflow teamWf; + @Mock private IAtsTask task; + @Mock private ArtifactId workPackageArt; + + @Mock private IAtsServices services; + @Mock private IAttributeResolver attributeResolver; + @Mock private IRelationResolver relationResolver; + + @Mock private ArtifactId activityArt; + @Mock private IAtsInsertionActivity activity; + + @Mock private IAtsInsertion insertion; + @Mock private IAtsProgram program; + @Mock private IAtsCountry country; + + @Mock private IAtsConfigItemFactory factory; + // @formatter:on + + private WorkPackageUtility util; + + @Before + public void setup() throws OseeCoreException { + MockitoAnnotations.initMocks(this); + when(teamWf.isTeamWorkflow()).thenReturn(true); + + when(task.getParentTeamWorkflow()).thenReturn(teamWf); + when(task.isTeamWorkflow()).thenReturn(false); + + when(services.getAttributeResolver()).thenReturn(attributeResolver); + when(services.getRelationResolver()).thenReturn(relationResolver); + when(services.getConfigItemFactory()).thenReturn(factory); + + util = new WorkPackageUtility(); + } + + @org.junit.Test + public void testGetWorkPackageArtifact() throws Exception { + when(attributeResolver.getSoleAttributeValue(teamWf, AtsAttributeTypes.WorkPackageGuid, null)).thenReturn(null); + Pair result = util.getWorkPackageArtifact(services, teamWf); + assertResult(result, null, false); + + when(attributeResolver.getSoleAttributeValue(teamWf, AtsAttributeTypes.WorkPackageGuid, null)).thenReturn("guid"); + when(services.getArtifactById("guid")).thenReturn(null); + result = util.getWorkPackageArtifact(services, teamWf); + assertResult(result, null, false); + + when(services.getArtifactById("guid")).thenReturn(workPackageArt); + result = util.getWorkPackageArtifact(services, teamWf); + assertResult(result, workPackageArt, false); + + when(attributeResolver.getSoleAttributeValue(task, AtsAttributeTypes.WorkPackageGuid, null)).thenReturn(null); + result = util.getWorkPackageArtifact(services, task); + assertResult(result, workPackageArt, true); + } + + @org.junit.Test + public void testGetInsertionActivity() throws Exception { + when(attributeResolver.getSoleAttributeValue(teamWf, AtsAttributeTypes.WorkPackageGuid, null)).thenReturn("guid"); + when(services.getArtifactById("guid")).thenReturn(null); + Pair result = util.getInsertionActivity(services, teamWf); + assertResult(result, null, false); + + when(services.getArtifactById("guid")).thenReturn(workPackageArt); + when(relationResolver.getRelatedOrNull(workPackageArt, + AtsRelationTypes.InsertionActivityToWorkPackage_InsertionActivity)).thenReturn(null); + result = util.getInsertionActivity(services, teamWf); + assertResult(result, null, false); + + when(relationResolver.getRelatedOrNull(workPackageArt, + AtsRelationTypes.InsertionActivityToWorkPackage_InsertionActivity)).thenReturn(activityArt); + when(factory.getInsertionActivity(activityArt)).thenReturn(activity); + result = util.getInsertionActivity(services, teamWf); + assertResult(result, activity, false); + + when(attributeResolver.getSoleAttributeValue(task, AtsAttributeTypes.WorkPackageGuid, null)).thenReturn(null); + result = util.getInsertionActivity(services, task); + assertResult(result, activity, true); + } + + @Test + public void testGetInsertion() throws Exception { + when(attributeResolver.getSoleAttributeValue(teamWf, AtsAttributeTypes.WorkPackageGuid, null)).thenReturn("guid"); + when(relationResolver.getRelatedOrNull(workPackageArt, + AtsRelationTypes.InsertionActivityToWorkPackage_InsertionActivity)).thenReturn(activityArt); + when(services.getArtifactById("guid")).thenReturn(workPackageArt); + when(factory.getInsertionActivity(activityArt)).thenReturn(null); + + Pair result = util.getInsertion(services, teamWf); + assertResult(result, null, false); + + when(factory.getInsertionActivity(activityArt)).thenReturn(activity); + when(relationResolver.getRelatedOrNull(activity, AtsRelationTypes.InsertionToInsertionActivity_Insertion, + IAtsInsertion.class)).thenReturn(insertion); + result = util.getInsertion(services, teamWf); + assertResult(result, insertion, false); + + when(attributeResolver.getSoleAttributeValue(task, AtsAttributeTypes.WorkPackageGuid, null)).thenReturn(null); + result = util.getInsertion(services, task); + assertResult(result, insertion, true); + } + + @Test + public void testGetProgram() throws Exception { + when(attributeResolver.getSoleAttributeValue(teamWf, AtsAttributeTypes.WorkPackageGuid, null)).thenReturn("guid"); + when(relationResolver.getRelatedOrNull(workPackageArt, + AtsRelationTypes.InsertionActivityToWorkPackage_InsertionActivity)).thenReturn(activityArt); + when(services.getArtifactById("guid")).thenReturn(workPackageArt); + when(factory.getInsertionActivity(activityArt)).thenReturn(null); + when(factory.getInsertionActivity(activityArt)).thenReturn(activity); + when(relationResolver.getRelatedOrNull(activity, AtsRelationTypes.InsertionToInsertionActivity_Insertion, + IAtsInsertion.class)).thenReturn(insertion); + + Pair result = util.getProgram(services, teamWf); + assertResult(result, null, false); + + when(relationResolver.getRelatedOrNull(insertion, AtsRelationTypes.ProgramToInsertion_Program, + IAtsProgram.class)).thenReturn(program); + result = util.getProgram(services, teamWf); + assertResult(result, program, false); + + when(attributeResolver.getSoleAttributeValue(task, AtsAttributeTypes.WorkPackageGuid, null)).thenReturn(null); + result = util.getProgram(services, task); + assertResult(result, program, true); + } + + @Test + public void testGetCountry() throws Exception { + when(attributeResolver.getSoleAttributeValue(teamWf, AtsAttributeTypes.WorkPackageGuid, null)).thenReturn("guid"); + when(relationResolver.getRelatedOrNull(workPackageArt, + AtsRelationTypes.InsertionActivityToWorkPackage_InsertionActivity)).thenReturn(activityArt); + when(services.getArtifactById("guid")).thenReturn(workPackageArt); + when(factory.getInsertionActivity(activityArt)).thenReturn(null); + when(factory.getInsertionActivity(activityArt)).thenReturn(activity); + when(relationResolver.getRelatedOrNull(activity, AtsRelationTypes.InsertionToInsertionActivity_Insertion, + IAtsInsertion.class)).thenReturn(insertion); + when(relationResolver.getRelatedOrNull(insertion, AtsRelationTypes.ProgramToInsertion_Program, + IAtsProgram.class)).thenReturn(program); + + Pair result = util.getCountry(services, teamWf); + assertResult(result, null, false); + + when(relationResolver.getRelatedOrNull(program, AtsRelationTypes.CountryToProgram_Country, + IAtsCountry.class)).thenReturn(country); + result = util.getCountry(services, teamWf); + assertResult(result, country, false); + + when(attributeResolver.getSoleAttributeValue(task, AtsAttributeTypes.WorkPackageGuid, null)).thenReturn(null); + result = util.getCountry(services, task); + assertResult(result, country, true); + } + + private void assertResult(Pair result, Object object, boolean inherited) { + assertNotNull(result); + assertEquals(result.getFirst(), object); + assertEquals(inherited, result.getSecond()); + } + +} -- cgit v1.2.3