| /********************************************************************************* |
| * Copyright (c) 2015-2020 Robert Bosch GmbH and others. |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Robert Bosch GmbH - initial API and implementation |
| ******************************************************************************** |
| */ |
| |
| package org.eclipse.app4mc.amalthea.editors.sirius.design.services; |
| |
| import static org.junit.Assert.assertEquals; |
| import static org.junit.Assert.assertFalse; |
| import static org.junit.Assert.assertNotNull; |
| import static org.junit.Assert.assertSame; |
| import static org.junit.Assert.assertTrue; |
| |
| import java.util.List; |
| |
| import org.eclipse.app4mc.amalthea.model.Amalthea; |
| import org.eclipse.app4mc.amalthea.model.AmaltheaFactory; |
| import org.eclipse.app4mc.amalthea.model.MappingModel; |
| import org.eclipse.app4mc.amalthea.model.OSModel; |
| import org.eclipse.app4mc.amalthea.model.OperatingSystem; |
| import org.eclipse.app4mc.amalthea.model.ProcessingUnit; |
| import org.eclipse.app4mc.amalthea.model.Scheduler; |
| import org.eclipse.app4mc.amalthea.model.SchedulerAllocation; |
| import org.eclipse.app4mc.amalthea.model.Task; |
| import org.eclipse.app4mc.amalthea.model.TaskAllocation; |
| import org.eclipse.app4mc.amalthea.model.TaskScheduler; |
| import org.junit.After; |
| import org.junit.Before; |
| import org.junit.Test; |
| |
| /** |
| * @author daniel.kunz@de.bosch.com |
| * |
| */ |
| public class MappingServiceTest { |
| |
| private MappingService mappingS = null; |
| |
| @Before |
| public void setUp() { |
| this.mappingS = new MappingService(); |
| } |
| |
| @After |
| public void tearDown() { |
| this.mappingS = null; |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getCoresOfMappingModel(org.eclipse.app4mc.amalthea.model.MappingModel)} |
| * . |
| */ |
| @Test |
| public void testGetCoresOfMappingModelNull() { |
| List<ProcessingUnit> result = this.mappingS.getCoresOfMappingModel(null); |
| assertNotNull(result); |
| assertTrue(result.isEmpty()); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getCoresOfMappingModel(org.eclipse.app4mc.amalthea.model.MappingModel)} |
| * . |
| */ |
| @Test |
| public void testGetCoresOfMappingModelEmptyModel() { |
| MappingModel mappingM = AmaltheaFactory.eINSTANCE.createMappingModel(); |
| List<ProcessingUnit> result = this.mappingS.getCoresOfMappingModel(mappingM); |
| assertNotNull(result); |
| assertTrue(result.isEmpty()); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getCoresOfMappingModel(org.eclipse.app4mc.amalthea.model.MappingModel)} |
| * . |
| */ |
| @Test |
| public void testGetCoresOfMappingModelEmptySchedAlloc() { |
| MappingModel mappingM = AmaltheaFactory.eINSTANCE.createMappingModel(); |
| mappingM.getSchedulerAllocation().add(AmaltheaFactory.eINSTANCE.createSchedulerAllocation()); |
| List<ProcessingUnit> result = this.mappingS.getCoresOfMappingModel(mappingM); |
| assertNotNull(result); |
| assertTrue(result.isEmpty()); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getCoresOfMappingModel(org.eclipse.app4mc.amalthea.model.MappingModel)} |
| * . |
| */ |
| @Test |
| public void testGetCoresOfMappingModelOneSchedAlloc() { |
| MappingModel mappingM = AmaltheaFactory.eINSTANCE.createMappingModel(); |
| SchedulerAllocation schedA = AmaltheaFactory.eINSTANCE.createSchedulerAllocation(); |
| ProcessingUnit core = AmaltheaFactory.eINSTANCE.createProcessingUnit(); |
| schedA.getResponsibility().add(core); |
| mappingM.getSchedulerAllocation().add(schedA); |
| List<ProcessingUnit> result = this.mappingS.getCoresOfMappingModel(mappingM); |
| assertNotNull(result); |
| assertFalse(result.isEmpty()); |
| assertEquals(1, result.size()); |
| assertSame(core, result.get(0)); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getSchedulersOfMappingModel(org.eclipse.app4mc.amalthea.model.MappingModel)} |
| * . |
| */ |
| @Test |
| public void testGetSchedulersOfMappingModelNull() { |
| List<Scheduler> result = this.mappingS.getSchedulersOfMappingModel(null); |
| assertNotNull(result); |
| assertTrue(result.isEmpty()); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getSchedulersOfMappingModel(org.eclipse.app4mc.amalthea.model.MappingModel)} |
| * . |
| */ |
| @Test |
| public void testGetSchedulersOfMappingModelEmptyMapping() { |
| MappingModel mappingM = AmaltheaFactory.eINSTANCE.createMappingModel(); |
| List<Scheduler> result = this.mappingS.getSchedulersOfMappingModel(mappingM); |
| assertNotNull(result); |
| assertTrue(result.isEmpty()); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getSchedulersOfMappingModel(org.eclipse.app4mc.amalthea.model.MappingModel)} |
| * . |
| */ |
| @Test |
| public void testGetSchedulersOfMappingModelOneEmptyMapping() { |
| MappingModel mappingM = AmaltheaFactory.eINSTANCE.createMappingModel(); |
| SchedulerAllocation schedA = AmaltheaFactory.eINSTANCE.createSchedulerAllocation(); |
| mappingM.getSchedulerAllocation().add(schedA); |
| List<Scheduler> result = this.mappingS.getSchedulersOfMappingModel(mappingM); |
| assertNotNull(result); |
| assertTrue(result.isEmpty()); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getSchedulersOfMappingModel(org.eclipse.app4mc.amalthea.model.MappingModel)} |
| * . |
| */ |
| @Test |
| public void testGetSchedulersOfMappingModelOneMapping() { |
| MappingModel mappingM = AmaltheaFactory.eINSTANCE.createMappingModel(); |
| SchedulerAllocation schedA = AmaltheaFactory.eINSTANCE.createSchedulerAllocation(); |
| Scheduler sched = AmaltheaFactory.eINSTANCE.createTaskScheduler(); |
| schedA.setScheduler(sched); |
| mappingM.getSchedulerAllocation().add(schedA); |
| List<Scheduler> result = this.mappingS.getSchedulersOfMappingModel(mappingM); |
| assertNotNull(result); |
| assertFalse(result.isEmpty()); |
| assertEquals(1, result.size()); |
| assertSame(sched, result.get(0)); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getCoresForScheduler(org.eclipse.app4mc.amalthea.model.Scheduler)} |
| * . |
| */ |
| @Test |
| public void testGetCoresForSchedulerNull() { |
| List<ProcessingUnit> result = this.mappingS.getCoresForScheduler(null); |
| assertNotNull(result); |
| assertTrue(result.isEmpty()); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getCoresForScheduler(org.eclipse.app4mc.amalthea.model.Scheduler)} |
| * . |
| */ |
| @Test |
| public void testGetCoresForSchedulerOnlyScheduler() { |
| Scheduler sched = AmaltheaFactory.eINSTANCE.createTaskScheduler(); |
| List<ProcessingUnit> result = this.mappingS.getCoresForScheduler(sched); |
| assertNotNull(result); |
| assertTrue(result.isEmpty()); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getCoresForScheduler(org.eclipse.app4mc.amalthea.model.Scheduler)} |
| * . |
| */ |
| @Test |
| public void testGetCoresForSchedulerSchedulerWithAmaltheaNullMapping() { |
| Amalthea amlt = AmaltheaFactory.eINSTANCE.createAmalthea(); |
| OSModel osM = AmaltheaFactory.eINSTANCE.createOSModel(); |
| amlt.setOsModel(osM); |
| OperatingSystem os = AmaltheaFactory.eINSTANCE.createOperatingSystem(); |
| osM.getOperatingSystems().add(os); |
| TaskScheduler sched = AmaltheaFactory.eINSTANCE.createTaskScheduler(); |
| os.getTaskSchedulers().add(sched); |
| List<ProcessingUnit> result = this.mappingS.getCoresForScheduler(sched); |
| assertNotNull(result); |
| assertTrue(result.isEmpty()); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getCoresForScheduler(org.eclipse.app4mc.amalthea.model.Scheduler)} |
| * . |
| */ |
| @Test |
| public void testGetCoresForSchedulerSchedulerWithAmaltheaEmptyMapping() { |
| MappingModel mappingM = AmaltheaFactory.eINSTANCE.createMappingModel(); |
| Amalthea amlt = AmaltheaFactory.eINSTANCE.createAmalthea(); |
| amlt.setMappingModel(mappingM); |
| OSModel osM = AmaltheaFactory.eINSTANCE.createOSModel(); |
| amlt.setOsModel(osM); |
| OperatingSystem os = AmaltheaFactory.eINSTANCE.createOperatingSystem(); |
| osM.getOperatingSystems().add(os); |
| TaskScheduler sched = AmaltheaFactory.eINSTANCE.createTaskScheduler(); |
| os.getTaskSchedulers().add(sched); |
| List<ProcessingUnit> result = this.mappingS.getCoresForScheduler(sched); |
| assertNotNull(result); |
| assertTrue(result.isEmpty()); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getCoresForScheduler(org.eclipse.app4mc.amalthea.model.Scheduler)} |
| * . |
| */ |
| @Test |
| public void testGetCoresForSchedulerSchedulerWithAmaltheaOneMapping() { |
| MappingModel mappingM = AmaltheaFactory.eINSTANCE.createMappingModel(); |
| Amalthea amlt = AmaltheaFactory.eINSTANCE.createAmalthea(); |
| amlt.setMappingModel(mappingM); |
| OSModel osM = AmaltheaFactory.eINSTANCE.createOSModel(); |
| amlt.setOsModel(osM); |
| OperatingSystem os = AmaltheaFactory.eINSTANCE.createOperatingSystem(); |
| osM.getOperatingSystems().add(os); |
| TaskScheduler sched = AmaltheaFactory.eINSTANCE.createTaskScheduler(); |
| os.getTaskSchedulers().add(sched); |
| SchedulerAllocation schedA = AmaltheaFactory.eINSTANCE.createSchedulerAllocation(); |
| schedA.setScheduler(sched); |
| mappingM.getSchedulerAllocation().add(schedA); |
| ProcessingUnit core = AmaltheaFactory.eINSTANCE.createProcessingUnit(); |
| schedA.getResponsibility().add(core); |
| List<ProcessingUnit> result = this.mappingS.getCoresForScheduler(sched); |
| assertNotNull(result); |
| assertFalse(result.isEmpty()); |
| assertEquals(1, result.size()); |
| assertSame(core, result.get(0)); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getCoresForScheduler(org.eclipse.app4mc.amalthea.model.Scheduler)} |
| * . |
| */ |
| @Test |
| public void testGetCoresForSchedulerSchedulerWithAmaltheaOneMappingOtherScheduler() { |
| MappingModel mappingM = AmaltheaFactory.eINSTANCE.createMappingModel(); |
| Amalthea amlt = AmaltheaFactory.eINSTANCE.createAmalthea(); |
| amlt.setMappingModel(mappingM); |
| OSModel osM = AmaltheaFactory.eINSTANCE.createOSModel(); |
| amlt.setOsModel(osM); |
| OperatingSystem os = AmaltheaFactory.eINSTANCE.createOperatingSystem(); |
| osM.getOperatingSystems().add(os); |
| TaskScheduler sched = AmaltheaFactory.eINSTANCE.createTaskScheduler(); |
| os.getTaskSchedulers().add(sched); |
| SchedulerAllocation schedA = AmaltheaFactory.eINSTANCE.createSchedulerAllocation(); |
| Scheduler sched2 = AmaltheaFactory.eINSTANCE.createTaskScheduler(); |
| schedA.setScheduler(sched2); |
| mappingM.getSchedulerAllocation().add(schedA); |
| ProcessingUnit core = AmaltheaFactory.eINSTANCE.createProcessingUnit(); |
| schedA.getResponsibility().add(core); |
| List<ProcessingUnit> result = this.mappingS.getCoresForScheduler(sched); |
| assertNotNull(result); |
| assertTrue(result.isEmpty()); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getTasksForScheduler(org.eclipse.app4mc.amalthea.model.Scheduler)} |
| * . |
| */ |
| @Test |
| public void testGetTasksForSchedulerNull() { |
| List<Task> result = this.mappingS.getTasksForScheduler(null); |
| assertNotNull(result); |
| assertTrue(result.isEmpty()); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getTasksForScheduler(org.eclipse.app4mc.amalthea.model.Scheduler)} |
| * . |
| */ |
| @Test |
| public void testGetTasksForSchedulerOnlyScheduler() { |
| Scheduler sched = AmaltheaFactory.eINSTANCE.createTaskScheduler(); |
| List<Task> result = this.mappingS.getTasksForScheduler(sched); |
| assertNotNull(result); |
| assertTrue(result.isEmpty()); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getTasksForScheduler(org.eclipse.app4mc.amalthea.model.Scheduler)} |
| * . |
| */ |
| @Test |
| public void testGetTasksForSchedulerEmptyMappingOneScheduler() { |
| Amalthea amlt = AmaltheaFactory.eINSTANCE.createAmalthea(); |
| MappingModel mappingM = AmaltheaFactory.eINSTANCE.createMappingModel(); |
| amlt.setMappingModel(mappingM); |
| TaskScheduler sched = AmaltheaFactory.eINSTANCE.createTaskScheduler(); |
| OSModel osM = AmaltheaFactory.eINSTANCE.createOSModel(); |
| amlt.setOsModel(osM); |
| OperatingSystem os = AmaltheaFactory.eINSTANCE.createOperatingSystem(); |
| osM.getOperatingSystems().add(os); |
| os.getTaskSchedulers().add(sched); |
| List<Task> result = this.mappingS.getTasksForScheduler(sched); |
| assertNotNull(result); |
| assertTrue(result.isEmpty()); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getTasksForScheduler(org.eclipse.app4mc.amalthea.model.Scheduler)} |
| * . |
| */ |
| @Test |
| public void testGetTasksForSchedulerNullMappingOneScheduler() { |
| Amalthea amlt = AmaltheaFactory.eINSTANCE.createAmalthea(); |
| TaskScheduler sched = AmaltheaFactory.eINSTANCE.createTaskScheduler(); |
| OSModel osM = AmaltheaFactory.eINSTANCE.createOSModel(); |
| amlt.setOsModel(osM); |
| OperatingSystem os = AmaltheaFactory.eINSTANCE.createOperatingSystem(); |
| osM.getOperatingSystems().add(os); |
| os.getTaskSchedulers().add(sched); |
| List<Task> result = this.mappingS.getTasksForScheduler(sched); |
| assertNotNull(result); |
| assertTrue(result.isEmpty()); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getTasksForScheduler(org.eclipse.app4mc.amalthea.model.Scheduler)} |
| * . |
| */ |
| @Test |
| public void testGetTasksForSchedulerOneMappingOneScheduler() { |
| Amalthea amlt = AmaltheaFactory.eINSTANCE.createAmalthea(); |
| MappingModel mappingM = AmaltheaFactory.eINSTANCE.createMappingModel(); |
| amlt.setMappingModel(mappingM); |
| TaskScheduler sched = AmaltheaFactory.eINSTANCE.createTaskScheduler(); |
| OSModel osM = AmaltheaFactory.eINSTANCE.createOSModel(); |
| amlt.setOsModel(osM); |
| OperatingSystem os = AmaltheaFactory.eINSTANCE.createOperatingSystem(); |
| osM.getOperatingSystems().add(os); |
| os.getTaskSchedulers().add(sched); |
| TaskAllocation taskA = AmaltheaFactory.eINSTANCE.createTaskAllocation(); |
| Task task = AmaltheaFactory.eINSTANCE.createTask(); |
| taskA.setTask(task); |
| taskA.setScheduler(sched); |
| mappingM.getTaskAllocation().add(taskA); |
| List<Task> result = this.mappingS.getTasksForScheduler(sched); |
| assertNotNull(result); |
| assertFalse(result.isEmpty()); |
| assertEquals(1, result.size()); |
| assertSame(task, result.get(0)); |
| } |
| |
| /** |
| * Test method for |
| * {@link org.eclipse.app4mc.amalthea.editors.sirius.design.services.MappingService#getTasksForScheduler(org.eclipse.app4mc.amalthea.model.Scheduler)} |
| * . |
| */ |
| @Test |
| public void testGetTasksForSchedulerOneMappingOtherScheduler() { |
| Amalthea amlt = AmaltheaFactory.eINSTANCE.createAmalthea(); |
| MappingModel mappingM = AmaltheaFactory.eINSTANCE.createMappingModel(); |
| amlt.setMappingModel(mappingM); |
| TaskScheduler sched = AmaltheaFactory.eINSTANCE.createTaskScheduler(); |
| OSModel osM = AmaltheaFactory.eINSTANCE.createOSModel(); |
| amlt.setOsModel(osM); |
| OperatingSystem os = AmaltheaFactory.eINSTANCE.createOperatingSystem(); |
| osM.getOperatingSystems().add(os); |
| os.getTaskSchedulers().add(sched); |
| TaskAllocation taskA = AmaltheaFactory.eINSTANCE.createTaskAllocation(); |
| Task task = AmaltheaFactory.eINSTANCE.createTask(); |
| taskA.setTask(task); |
| TaskScheduler sched1 = AmaltheaFactory.eINSTANCE.createTaskScheduler(); |
| taskA.setScheduler(sched1); |
| mappingM.getTaskAllocation().add(taskA); |
| List<Task> result = this.mappingS.getTasksForScheduler(sched); |
| assertNotNull(result); |
| assertTrue(result.isEmpty()); |
| } |
| } |