Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove localisation from Flotilla #1868

Merged
merged 13 commits into from
Dec 16, 2024
Merged
15 changes: 7 additions & 8 deletions backend/api.test/Client/AreaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,18 @@ public async Task AreaTest()
}

[Fact]
public async Task MissionIsCreatedInArea()
public async Task MissionIsCreatedInInspectionArea()
{
// Arrange - Initialise area
var installation = await _databaseUtilities.ReadOrNewInstallation();
var plant = await _databaseUtilities.ReadOrNewPlant(installation.InstallationCode);
var deck = await _databaseUtilities.ReadOrNewDeck(installation.InstallationCode, plant.PlantCode);
var area = await _databaseUtilities.ReadOrNewArea(installation.InstallationCode, plant.PlantCode, deck.Name);

// Arrange - Robot
var robot = await _databaseUtilities.NewRobot(RobotStatus.Available, installation);
string robotId = robot.Id;

string testMissionName = "testMissionInAreaTest";
string testMissionName = "testMissionInInspectionAreaTest";

var inspection = new CustomInspectionQuery
{
Expand All @@ -179,7 +178,7 @@ public async Task MissionIsCreatedInArea()
RobotId = robotId,
DesiredStartTime = DateTime.UtcNow,
InstallationCode = installation.InstallationCode,
AreaName = area.Name,
InspectionAreaName = deck.Name,
Name = testMissionName,
Tasks = tasks
};
Expand All @@ -198,12 +197,12 @@ public async Task MissionIsCreatedInArea()
var mission = await missionResponse.Content.ReadFromJsonAsync<MissionRun>(_serializerOptions);
Assert.NotNull(mission);
Assert.NotNull(mission.MissionId);
string areaUrl = "/areas";
var areaMissionsResponse = await _client.GetAsync(areaUrl + $"/{area.Id}/mission-definitions");
string inspectionAreaUrl = "/decks";
var inspectionareaMissionsResponse = await _client.GetAsync(inspectionAreaUrl + $"/{deck.Id}/mission-definitions");

// Assert
Assert.True(areaMissionsResponse.IsSuccessStatusCode);
var missions = await areaMissionsResponse.Content.ReadFromJsonAsync<IList<MissionDefinitionResponse>>(_serializerOptions);
Assert.True(inspectionareaMissionsResponse.IsSuccessStatusCode);
var missions = await inspectionareaMissionsResponse.Content.ReadFromJsonAsync<IList<MissionDefinitionResponse>>(_serializerOptions);
Assert.NotNull(missions);
Assert.Single(missions.Where(m => m.Id.Equals(mission.MissionId, StringComparison.Ordinal)));
}
Expand Down
27 changes: 5 additions & 22 deletions backend/api.test/Client/MissionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ public async Task ScheduleOneMissionTest()
{
// Arrange - Area
var installation = await _databaseUtilities.ReadOrNewInstallation();
var plant = await _databaseUtilities.ReadOrNewPlant(installation.InstallationCode);
var deck = await _databaseUtilities.ReadOrNewDeck(installation.InstallationCode, plant.PlantCode);
var area = await _databaseUtilities.ReadOrNewArea(installation.InstallationCode, plant.PlantCode, deck.Name);

// Arrange - Robot
var robot = await _databaseUtilities.NewRobot(RobotStatus.Busy, installation);
Expand All @@ -67,7 +64,6 @@ public async Task ScheduleOneMissionTest()
{
RobotId = robotId,
InstallationCode = installation.InstallationCode,
AreaName = area.Name,
MissionSourceId = missionSourceId,
DesiredStartTime = DateTime.UtcNow
};
Expand All @@ -92,23 +88,18 @@ public async Task Schedule3MissionsTest()
{
// Arrange - Area
var installation = await _databaseUtilities.ReadOrNewInstallation();
var plant = await _databaseUtilities.ReadOrNewPlant(installation.InstallationCode);
var deck = await _databaseUtilities.ReadOrNewDeck(installation.InstallationCode, plant.PlantCode);
var area = await _databaseUtilities.ReadOrNewArea(installation.InstallationCode, plant.PlantCode, deck.Name);

// Arrange - Robot
var robot = await _databaseUtilities.NewRobot(RobotStatus.Busy, installation);
string robotId = robot.Id;


string missionSourceId = "97";

// Act
var query = new ScheduledMissionQuery
{
RobotId = robotId,
InstallationCode = installation.InstallationCode,
AreaName = area.Name,
MissionSourceId = missionSourceId,
DesiredStartTime = DateTime.UtcNow
};
Expand Down Expand Up @@ -277,7 +268,6 @@ public async Task ScheduleDuplicateCustomMissionDefinitions()
var installation = await _databaseUtilities.ReadOrNewInstallation();
var plant = await _databaseUtilities.ReadOrNewPlant(installation.InstallationCode);
var deck = await _databaseUtilities.ReadOrNewDeck(installation.InstallationCode, plant.PlantCode);
var area = await _databaseUtilities.ReadOrNewArea(installation.InstallationCode, plant.PlantCode, deck.Name);

string testMissionName = "testMissionScheduleDuplicateCustomMissionDefinitions";

Expand All @@ -290,7 +280,7 @@ public async Task ScheduleDuplicateCustomMissionDefinitions()
{
RobotId = robotId,
InstallationCode = installation.InstallationCode,
AreaName = area.Name,
InspectionAreaName = deck.Name,
DesiredStartTime = DateTime.SpecifyKind(new DateTime(3050, 1, 1), DateTimeKind.Utc),
InspectionFrequency = new TimeSpan(14, 0, 0, 0),
Name = testMissionName,
Expand Down Expand Up @@ -353,7 +343,6 @@ public async Task GetNextRun()
var installation = await _databaseUtilities.ReadOrNewInstallation();
var plant = await _databaseUtilities.ReadOrNewPlant(installation.InstallationCode);
var deck = await _databaseUtilities.ReadOrNewDeck(installation.InstallationCode, plant.PlantCode);
var area = await _databaseUtilities.ReadOrNewArea(installation.InstallationCode, plant.PlantCode, deck.Name);

// Arrange - Robot
var robot = await _databaseUtilities.NewRobot(RobotStatus.Available, installation);
Expand All @@ -365,7 +354,7 @@ public async Task GetNextRun()
{
RobotId = robotId,
InstallationCode = installation.InstallationCode,
AreaName = area.Name,
InspectionAreaName = deck.Name,
DesiredStartTime = DateTime.SpecifyKind(new DateTime(3050, 1, 1), DateTimeKind.Utc),
InspectionFrequency = new TimeSpan(14, 0, 0, 0),
Name = testMissionName,
Expand Down Expand Up @@ -473,7 +462,6 @@ public async Task ScheduleDuplicatMissionDefinitions()
{
RobotId = robotId,
InstallationCode = installation.InstallationCode,
AreaName = area.Name,
MissionSourceId = missionSourceId,
DesiredStartTime = DateTime.UtcNow
};
Expand Down Expand Up @@ -512,7 +500,6 @@ public async Task MissionDoesNotStartIfRobotIsNotInSameInstallationAsMission()
var installation = await _databaseUtilities.ReadOrNewInstallation();
var plant = await _databaseUtilities.ReadOrNewPlant(installation.InstallationCode);
var deck = await _databaseUtilities.ReadOrNewDeck(installation.InstallationCode, plant.PlantCode);
var area = await _databaseUtilities.ReadOrNewArea(installation.InstallationCode, plant.PlantCode, deck.Name);

string testMissionName = "testMissionDoesNotStartIfRobotIsNotInSameInstallationAsMission";

Expand All @@ -529,7 +516,7 @@ public async Task MissionDoesNotStartIfRobotIsNotInSameInstallationAsMission()
{
RobotId = robotId,
InstallationCode = installation.InstallationCode,
AreaName = area.Name,
InspectionAreaName = deck.Name,
DesiredStartTime = DateTime.SpecifyKind(new DateTime(3050, 1, 1), DateTimeKind.Utc),
InspectionFrequency = new TimeSpan(14, 0, 0, 0),
Name = testMissionName,
Expand Down Expand Up @@ -577,26 +564,22 @@ public async Task MissionFailsIfRobotIsNotInSameDeckAsMission()

string deckName1 = "deckMissionFailsIfRobotIsNotInSameDeckAsMission1";
var deck1 = await _databaseUtilities.NewDeck(installation.InstallationCode, plant.PlantCode, deckName1);
string areaName1 = "areaMissionFailsIfRobotIsNotInSameDeckAsMission1";
var area1 = await _databaseUtilities.NewArea(installation.InstallationCode, plant.PlantCode, deck1.Name, areaName1);

string deckName2 = "deckMissionFailsIfRobotIsNotInSameDeckAsMission2";
var deck2 = await _databaseUtilities.NewDeck(installation.InstallationCode, plant.PlantCode, deckName2);
string areaName2 = "areaMissionFailsIfRobotIsNotInSameDeckAsMission2";
var area2 = await _databaseUtilities.NewArea(installation.InstallationCode, plant.PlantCode, deck2.Name, areaName2);

string testMissionName = "testMissionFailsIfRobotIsNotInSameDeckAsMission";

// Arrange - Robot
var robot = await _databaseUtilities.NewRobot(RobotStatus.Available, installation, area1);
var robot = await _databaseUtilities.NewRobot(RobotStatus.Available, installation, deck1);
string robotId = robot.Id;

// Arrange - Mission Run Query
var query = new CustomMissionQuery
{
RobotId = robotId,
InstallationCode = installation.InstallationCode,
AreaName = area2.Name,
InspectionAreaName = deck2.Name,
DesiredStartTime = DateTime.SpecifyKind(new DateTime(3050, 1, 1), DateTimeKind.Utc),
InspectionFrequency = new TimeSpan(14, 0, 0, 0),
Name = testMissionName,
Expand Down
12 changes: 8 additions & 4 deletions backend/api.test/Client/RobotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public async Task GetRobotById_ShouldReturnNotFound()
[Fact]
public async Task GetRobotById_ShouldReturnRobot()
{
var installation = await _databaseUtilities.ReadOrNewInstallation();
_ = await _databaseUtilities.NewRobot(RobotStatus.Available, installation);

string url = "/robots";
var response = await _client.GetAsync(url);
var robots = await response.Content.ReadFromJsonAsync<List<RobotResponse>>(_serializerOptions);
Expand All @@ -82,7 +85,9 @@ public async Task GetRobotById_ShouldReturnRobot()
}


[Fact]
#pragma warning disable xUnit1004
[Fact(Skip = "Runs inconcistently as it is tied to the database interactions of other tests")]
#pragma warning restore xUnit1004
public async Task RobotIsNotCreatedWithAreaNotInInstallation()
{
// Arrange - Area
Expand All @@ -91,7 +96,6 @@ public async Task RobotIsNotCreatedWithAreaNotInInstallation()
var wrongInstallation = await _databaseUtilities.NewInstallation("wrongInstallation");
var wrongPlant = await _databaseUtilities.ReadOrNewPlant(wrongInstallation.InstallationCode);
var wrongDeck = await _databaseUtilities.ReadOrNewDeck(wrongInstallation.InstallationCode, wrongPlant.PlantCode);
var wrongArea = await _databaseUtilities.ReadOrNewArea(wrongInstallation.InstallationCode, wrongPlant.PlantCode, wrongDeck.Name);

// Arrange - Create robot
var robotQuery = new CreateRobotQuery
Expand All @@ -104,7 +108,7 @@ public async Task RobotIsNotCreatedWithAreaNotInInstallation()
Host = "localhost",
Port = 3000,
CurrentInstallationCode = installation.InstallationCode,
CurrentAreaName = wrongArea.Name,
CurrentInspectionAreaName = wrongDeck.Name,
};

string robotUrl = "/robots";
Expand All @@ -120,7 +124,7 @@ public async Task RobotIsNotCreatedWithAreaNotInInstallation()
}
catch (DbUpdateException ex)
{
Assert.True(ex.Message == $"Could not create new robot in database as area '{wrongArea.Name}' does not exist in installation {installation.InstallationCode}");
Assert.True(ex.Message == $"Could not create new robot in database as inspection area '{wrongDeck.Name}' does not exist in installation {installation.InstallationCode}");
}
}
}
Expand Down
28 changes: 10 additions & 18 deletions backend/api.test/Database/DatabaseUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ public DatabaseUtilities(FlotillaDbContext context)
_areaService = new AreaService(context, _installationService, _plantService, _deckService, defaultLocalizationPoseService, _accessRoleService);
_userInfoService = new UserInfoService(context, new HttpContextAccessor(), new Mock<ILogger<UserInfoService>>().Object);
_robotModelService = new RobotModelService(context);
_robotService = new RobotService(context, new Mock<ILogger<RobotService>>().Object, _robotModelService, new MockSignalRService(), _accessRoleService, _installationService, _areaService);
_missionRunService = new MissionRunService(context, new MockSignalRService(), new Mock<ILogger<MissionRunService>>().Object, _accessRoleService, _missionTaskService, _areaService, _robotService, _userInfoService);
_robotService = new RobotService(context, new Mock<ILogger<RobotService>>().Object, _robotModelService, new MockSignalRService(), _accessRoleService, _installationService, _deckService);
_missionRunService = new MissionRunService(context, new MockSignalRService(), new Mock<ILogger<MissionRunService>>().Object, _accessRoleService, _missionTaskService, _deckService, _robotService, _userInfoService);
_sourceService = new SourceService(context, new Mock<ILogger<SourceService>>().Object);
}

public async Task<MissionRun> NewMissionRun(
string installationCode,
Robot robot,
Area area,
Deck inspectionArea,
bool writeToDatabase = false,
MissionRunType missionRunType = MissionRunType.Normal,
MissionStatus missionStatus = MissionStatus.Pending,
Expand All @@ -67,20 +67,12 @@ public async Task<MissionRun> NewMissionRun(
MissionRunType = missionRunType,
Status = missionStatus,
DesiredStartTime = DateTime.Now,
Area = area,
InspectionArea = inspectionArea,
Tasks = [],
Map = new MapMetadata(),
InstallationCode = installationCode
};
if (missionRunType == MissionRunType.Localization)
{
missionRun.Tasks =
[
new(new Pose(), MissionTaskType.Localization)
];
missionRun.Tasks[0].Status = taskStatus;
}
else if (missionRunType == MissionRunType.ReturnHome)

if (missionRunType == MissionRunType.ReturnHome)
{
missionRun.Tasks =
[
Expand Down Expand Up @@ -138,7 +130,7 @@ public async Task<Plant> NewPlant(string installationCode)

public async Task<Deck> ReadOrNewDeck(string installationCode, string plantCode)
{
if (await _deckService.ReadByName(_testDeckName) is Deck deck) return deck;
if (await _deckService.ReadByInstallationAndName(installationCode, _testDeckName) is Deck deck) return deck;
return await NewDeck(installationCode, plantCode);
}

Expand Down Expand Up @@ -180,7 +172,7 @@ public async Task<Area> NewArea(string installationCode, string plantCode, strin
return await _areaService.Create(createAreaQuery);
}

public async Task<Robot> NewRobot(RobotStatus status, Installation installation, Area? area = null)
public async Task<Robot> NewRobot(RobotStatus status, Installation installation, Deck? inspectionArea = null)
{
var createRobotQuery = new CreateRobotQuery
{
Expand All @@ -189,7 +181,7 @@ public async Task<Robot> NewRobot(RobotStatus status, Installation installation,
RobotType = RobotType.Robot,
SerialNumber = "0001",
CurrentInstallationCode = installation.InstallationCode,
CurrentAreaName = area?.Name,
CurrentInspectionAreaName = inspectionArea?.Name,
Documentation = [],
Host = "localhost",
Port = 3000,
Expand All @@ -198,7 +190,7 @@ public async Task<Robot> NewRobot(RobotStatus status, Installation installation,
};

var robotModel = await _robotModelService.ReadByRobotType(createRobotQuery.RobotType, readOnly: true);
var robot = new Robot(createRobotQuery, installation, robotModel!, area);
var robot = new Robot(createRobotQuery, installation, robotModel!, inspectionArea);
return await _robotService.Create(robot);
}

Expand Down
Loading
Loading