Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,31 @@
package org.bitrepository.alarm;

import org.jaccept.structure.ExtendedTestCase;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

public class AlarmExceptionTest extends ExtendedTestCase {

@Test(groups = {"regressiontest"})
@Test
@Tag("regressiontest")
public void alarmExceptionTest() throws Exception {
addDescription("Tests that AlarmExceptions can be thrown.");
String alarmError = "The message of the alarm exception";
try {
throw new AlarmException(alarmError);
} catch (AlarmException e) {
Assert.assertEquals(e.getMessage(), alarmError);
Assert.assertNull(e.getCause());
Assertions.assertEquals(e.getMessage(), alarmError);
Assertions.assertNull(e.getCause());
}

String otherError = "This is the message of the included exception";
try {
throw new AlarmException(alarmError, new Exception(otherError));
} catch (AlarmException e) {
Assert.assertEquals(e.getMessage(), alarmError);
Assert.assertNotNull(e.getCause());
Assert.assertEquals(e.getCause().getMessage(), otherError);
Assertions.assertEquals(e.getMessage(), alarmError);
Assertions.assertNotNull(e.getCause());
Assertions.assertEquals(e.getCause().getMessage(), otherError);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,39 @@
import org.bitrepository.bitrepositorymessages.AlarmMessage;
import org.bitrepository.bitrepositorymessages.Message;
import org.bitrepository.protocol.IntegrationTest;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import static org.testng.AssertJUnit.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class AlarmHandlerTest extends IntegrationTest {
@Test(groups = {"regressiontest"})
@Test @Tag("regressiontest")
public void alarmMediatorTest() throws Exception {
addDescription("Test the mediator handling of alarm messages.");
addStep("Setup mediator and create alarm handler.", "Should be ok.");
AlarmMediator mediator = new AlarmMediator(messageBus, alarmDestinationID);
MockAlarmHandler alarmHandler = new MockAlarmHandler();
mediator.addHandler(alarmHandler);
Assert.assertEquals(alarmHandler.getCallsForClose(), 0);
Assert.assertEquals(alarmHandler.getCallsForHandleAlarm(), 0);
assertEquals(0, alarmHandler.getCallsForClose());
assertEquals(0, alarmHandler.getCallsForHandleAlarm());

addStep("Try giving it a non-alarm message", "Should not call the alarm handler.");
Message msg = new Message();
mediator.onMessage(msg, null);
assertEquals(alarmHandler.getCallsForClose(), 0);
Assert.assertEquals(alarmHandler.getCallsForHandleAlarm(), 0);
assertEquals(0, alarmHandler.getCallsForClose());
assertEquals(0, alarmHandler.getCallsForHandleAlarm());

addStep("Giv the mediator an AlarmMessage", "Should be sent to the alarm handler");
AlarmMessage alarmMsg = new AlarmMessage();
mediator.onMessage(alarmMsg, null);
Assert.assertEquals(alarmHandler.getCallsForClose(), 0);
Assert.assertEquals(alarmHandler.getCallsForHandleAlarm(), 1);
assertEquals(0, alarmHandler.getCallsForClose());
assertEquals(1, alarmHandler.getCallsForHandleAlarm());

addStep("Close the mediator.", "Should also close the alarm handler.");
mediator.close();
Assert.assertEquals(alarmHandler.getCallsForClose(), 1);
Assert.assertEquals(alarmHandler.getCallsForHandleAlarm(), 1);
assertEquals(1, alarmHandler.getCallsForClose());
assertEquals(1, alarmHandler.getCallsForHandleAlarm());
}

protected class MockAlarmHandler implements AlarmHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@

import org.bitrepository.bitrepositoryelements.AlarmCode;
import org.jaccept.structure.ExtendedTestCase;
import org.testng.Assert;
import org.testng.annotations.Test;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import java.util.Date;

/**
* Runs ExtendedTestCase with a regression test.
*/

public class AlarmDatabaseExtractionModelTest extends ExtendedTestCase {
@Test(groups = {"regressiontest"})
@Test @Tag("regressiontest")
public void alarmExceptionTest() throws Exception {
addDescription("Test the AlarmDatabaseExtractionModel class");
addStep("Define constants etc.", "Should be OK");
Expand All @@ -42,53 +42,53 @@ public void alarmExceptionTest() throws Exception {
addStep("Create an empty model", "Should be populated with nulls.");
AlarmDatabaseExtractionModel model = new AlarmDatabaseExtractionModel(null, null, null, null, null, null, null, ascending);

Assert.assertNull(model.getAlarmCode());
Assert.assertNull(model.getComponentId());
Assert.assertNull(model.getEndDate());
Assert.assertNull(model.getFileID());
Assert.assertNull(model.getStartDate());
Assert.assertNull(model.getCollectionID());
Assert.assertEquals(model.getAscending(), ascending);
Assert.assertEquals(model.getMaxCount().intValue(), Integer.MAX_VALUE);
Assertions.assertNull(model.getAlarmCode());
Assertions.assertNull(model.getComponentId());
Assertions.assertNull(model.getEndDate());
Assertions.assertNull(model.getFileID());
Assertions.assertNull(model.getStartDate());
Assertions.assertNull(model.getCollectionID());
Assertions.assertEquals(model.getAscending(), ascending);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have mostly remembered to swap arguments of assertEquals() and assertNotEquals(). Seems you forgot in some places throughout this pull request, like here and few more times in this file. IntelliJ IDEA correctly warns about it most of the times (at least mine does, I believe it’s a default setting). We have agreed that this can be fixed in a different pull request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found out that there it is possible to change everywhere that there is a warning in the project, so it should be done now.

Assertions.assertEquals(Integer.MAX_VALUE, model.getMaxCount().intValue());

addStep("Test the AlarmCode", "Should be able to put a new one in and extract it again.");
AlarmCode defaultAlarmCode = AlarmCode.COMPONENT_FAILURE;
model.setAlarmCode(defaultAlarmCode);
Assert.assertEquals(model.getAlarmCode(), defaultAlarmCode);
Assertions.assertEquals(model.getAlarmCode(), defaultAlarmCode);

addStep("Test the ascending", "Should be able to put a new one in and extract it again.");
boolean defaultAscending = false;
model.setAscending(defaultAscending);
Assert.assertEquals(model.getAscending(), defaultAscending);
Assertions.assertEquals(model.getAscending(), defaultAscending);

addStep("Test the ComponentID", "Should be able to put a new one in and extract it again.");
String defaultComponentID = "DefaultComponentID";
model.setComponentId(defaultComponentID);
Assert.assertEquals(model.getComponentId(), defaultComponentID);
Assertions.assertEquals(model.getComponentId(), defaultComponentID);

addStep("Test the EndDate", "Should be able to put a new one in and extract it again.");
Date defaultEndDate = new Date(987654321);
model.setEndDate(defaultEndDate);
Assert.assertEquals(model.getEndDate(), defaultEndDate);
Assertions.assertEquals(model.getEndDate(), defaultEndDate);

addStep("Test the FileID", "Should be able to put a new one in and extract it again.");
String defaultFileID = "DefaultFileID";
model.setFileID(defaultFileID);
Assert.assertEquals(model.getFileID(), defaultFileID);
Assertions.assertEquals(model.getFileID(), defaultFileID);

addStep("Test the MaxCount", "Should be able to put a new one in and extract it again.");
Integer defaultMaxCount = 192837456;
model.setMaxCount(defaultMaxCount);
Assert.assertEquals(model.getMaxCount(), defaultMaxCount);
Assertions.assertEquals(model.getMaxCount(), defaultMaxCount);

addStep("Test the StartDate", "Should be able to put a new one in and extract it again.");
Date defaultStartDate = new Date(123456789);
model.setStartDate(defaultStartDate);
Assert.assertEquals(model.getStartDate(), defaultStartDate);
Assertions.assertEquals(model.getStartDate(), defaultStartDate);

addStep("Test the CollectionID", "Should be able to put a new one in and extract it again.");
String collectionID = "collection1";
model.setCollectionID(collectionID);
Assert.assertEquals(model.getCollectionID(), collectionID);
Assertions.assertEquals(model.getCollectionID(), collectionID);
}
}
Loading