-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit test for InfrastructureInstance
- Loading branch information
1 parent
4c88de3
commit 1cec564
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
...est/java/org/eclipse/mosaic/fed/infrastructure/ambassador/InfrastructureInstanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (C) 2023 LEIDOS. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package org.eclipse.mosaic.fed.infrastructure.ambassador; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import java.net.DatagramSocket; | ||
import java.net.InetAddress; | ||
import java.util.ArrayList; | ||
|
||
import org.eclipse.mosaic.lib.geo.CartesianPoint; | ||
import org.eclipse.mosaic.lib.objects.detector.Detector; | ||
import org.eclipse.mosaic.lib.objects.detector.DetectorType; | ||
import org.eclipse.mosaic.lib.objects.detector.Orientation; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.internal.util.reflection.FieldSetter; | ||
|
||
public class InfrastructureInstanceTest { | ||
|
||
private DatagramSocket socket; | ||
|
||
private InfrastructureInstance instance; | ||
|
||
private InetAddress address; | ||
|
||
@Before | ||
public void setup() throws NoSuchFieldException{ | ||
address = mock(InetAddress.class); | ||
socket = mock(DatagramSocket.class); | ||
ArrayList<Detector> sensors = new ArrayList<>(); | ||
sensors.add( | ||
new Detector( | ||
"sensor1", | ||
DetectorType.SEMANTIC_LIDAR, | ||
new Orientation( 0.0,0.0,0.0), | ||
CartesianPoint.ORIGO)); | ||
sensors.add( | ||
new Detector( | ||
"NewSensor", | ||
DetectorType.SEMANTIC_LIDAR, | ||
new Orientation( 20.0,20.0,0.0), | ||
CartesianPoint.ORIGO)); | ||
instance = new InfrastructureInstance( | ||
"SomeID", | ||
address, | ||
3456, | ||
5667, | ||
8888, | ||
CartesianPoint.ORIGO, | ||
sensors); | ||
FieldSetter.setField(instance, instance.getClass().getDeclaredField("rxMsgsSocket"), socket); | ||
|
||
} | ||
@Test | ||
public void testContainsSensor() { | ||
assertTrue(instance.containsSensor("NewSensor")); | ||
assertTrue(instance.containsSensor("sensor1")); | ||
assertFalse(instance.containsSensor("otherSensor")); | ||
} | ||
|
||
@Test | ||
public void testGetterSetterConstructor() { | ||
assertEquals(instance.getInfrastructureId(), "SomeID"); | ||
assertEquals(instance.getLocation(), CartesianPoint.ORIGO); | ||
assertEquals(instance.getRxMessagePort(), 3456); | ||
assertEquals(instance.getTimeSyncPort(), 5667); | ||
} | ||
} |