-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from OsiriX-Foundation/feat/unit_tests_servic…
…e_coverage feat: add service unit tests + coverage on new code + deactivate previous not working unit tests
- Loading branch information
Showing
34 changed files
with
2,388 additions
and
146 deletions.
There are no files selected for viewing
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
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
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
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
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
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
66 changes: 66 additions & 0 deletions
66
src/test/java/org/karnak/backend/enums/ProfileItemTypeTest.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,66 @@ | ||
/* | ||
* Copyright (c) 2021 Karnak Team and other contributors. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the Eclipse | ||
* Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0, or the Apache | ||
* License, Version 2.0 which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
package org.karnak.backend.enums; | ||
|
||
import org.junit.Assert; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
class ProfileItemTypeTest { | ||
|
||
@Test | ||
void should_retrieve_code_meaning() { | ||
|
||
// Call enum | ||
// Test results | ||
Assert.assertEquals( | ||
"Basic Application Confidentiality Profile", | ||
ProfileItemType.getCodeMeaning("basic.dicom.profile")); | ||
Assert.assertEquals( | ||
"Clean Pixel Data Option", ProfileItemType.getCodeMeaning("clean.pixel.data")); | ||
Assert.assertEquals(null, ProfileItemType.getCodeMeaning("replace.uid")); | ||
Assert.assertEquals(null, ProfileItemType.getCodeMeaning("action.on.specific.tags")); | ||
Assert.assertEquals( | ||
"Retain Safe Private Option", ProfileItemType.getCodeMeaning("action.on.privatetags")); | ||
Assert.assertEquals( | ||
"Retain Longitudinal Temporal Information Modified Dates Option", | ||
ProfileItemType.getCodeMeaning("action.on.dates")); | ||
Assert.assertEquals(null, ProfileItemType.getCodeMeaning("expression.on.tags")); | ||
} | ||
|
||
@Test | ||
void should_retrieve_code_value() { | ||
|
||
// Call enum | ||
// Test results | ||
Assert.assertEquals("113100", ProfileItemType.getCodeValue("basic.dicom.profile")); | ||
Assert.assertEquals("113101", ProfileItemType.getCodeValue("clean.pixel.data")); | ||
Assert.assertEquals(null, ProfileItemType.getCodeValue("replace.uid")); | ||
Assert.assertEquals(null, ProfileItemType.getCodeValue("action.on.specific.tags")); | ||
Assert.assertEquals("113111", ProfileItemType.getCodeValue("action.on.privatetags")); | ||
Assert.assertEquals("113107", ProfileItemType.getCodeValue("action.on.dates")); | ||
Assert.assertEquals(null, ProfileItemType.getCodeValue("expression.on.tags")); | ||
} | ||
|
||
@Test | ||
void when_code_value_alias_not_found_should_return_null() { | ||
// Call enum | ||
// Test results | ||
Assert.assertEquals(null, ProfileItemType.getCodeValue("not.found")); | ||
} | ||
|
||
@Test | ||
void when_code_meaning_alias_not_found_should_return_null() { | ||
// Call enum | ||
// Test results | ||
Assert.assertEquals(null, ProfileItemType.getCodeMeaning("not.found")); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/test/java/org/karnak/backend/model/editor/DeIdentifyEditorTest.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,66 @@ | ||
/* | ||
* Copyright (c) 2021 Karnak Team and other contributors. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the Eclipse | ||
* Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0, or the Apache | ||
* License, Version 2.0 which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
package org.karnak.backend.model.editor; | ||
|
||
import org.dcm4che3.data.Attributes; | ||
import org.dcm4che3.data.Tag; | ||
import org.dcm4che3.data.VR; | ||
import org.junit.Assert; | ||
import org.junit.jupiter.api.Test; | ||
import org.karnak.backend.data.entity.DestinationEntity; | ||
import org.karnak.backend.data.entity.ProfileEntity; | ||
import org.karnak.backend.data.entity.ProjectEntity; | ||
import org.karnak.backend.enums.PseudonymType; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.weasis.dicom.param.AttributeEditorContext; | ||
import org.weasis.dicom.param.DicomNode; | ||
|
||
@SpringBootTest | ||
class DeIdentifyEditorTest { | ||
|
||
@Test | ||
void should_apply_to_dicom_object() { | ||
// Init data | ||
Attributes attributes = new Attributes(); | ||
DicomNode source = new DicomNode("source"); | ||
DicomNode destination = new DicomNode("destination"); | ||
AttributeEditorContext attributeEditorContext = | ||
new AttributeEditorContext("tsuid", source, destination); | ||
DestinationEntity destinationEntity = new DestinationEntity(); | ||
ProfileEntity profileEntity = new ProfileEntity(); | ||
ProjectEntity projectEntity = new ProjectEntity(); | ||
projectEntity.setProfileEntity(profileEntity); | ||
destinationEntity.setProjectEntity(projectEntity); | ||
destinationEntity.setPseudonymType(PseudonymType.EXTID_IN_TAG); | ||
destinationEntity.setTag("0008,0080"); | ||
destinationEntity.setSavePseudonym(false); | ||
destinationEntity.setPseudonymAsPatientName(true); | ||
byte[] tabByte = new byte[16]; | ||
tabByte[0] = 1; | ||
projectEntity.setSecret(tabByte); | ||
attributes.setString(Tag.PatientID, VR.SH, "patientID"); | ||
attributes.setString(Tag.SeriesInstanceUID, VR.SH, "seriesInstanceUID"); | ||
attributes.setString(Tag.SOPInstanceUID, VR.SH, "sopInstanceUID"); | ||
attributes.setString(Tag.IssuerOfPatientID, VR.SH, "issuerOfPatientID"); | ||
attributes.setString(Tag.PixelData, VR.SH, "pixelData"); | ||
attributes.setString(Tag.SOPClassUID, VR.SH, "1.2.840.10008.5.1.4.1.1.88.74"); | ||
attributes.setString(Tag.BurnedInAnnotation, VR.SH, "YES"); | ||
attributes.setString(Tag.StationName, VR.SH, "stationName"); | ||
attributes.setString(524416, VR.SH, "pseudonym"); | ||
DeIdentifyEditor deIdentifyEditor = new DeIdentifyEditor(destinationEntity); | ||
|
||
// Call method | ||
deIdentifyEditor.apply(attributes, attributeEditorContext); | ||
|
||
// Test results | ||
Assert.assertEquals("NONE", attributeEditorContext.getAbort().name()); | ||
Assert.assertNull(attributeEditorContext.getMaskArea()); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
src/test/java/org/karnak/backend/model/editor/FilterEditorTest.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,91 @@ | ||
/* | ||
* Copyright (c) 2021 Karnak Team and other contributors. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the Eclipse | ||
* Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0, or the Apache | ||
* License, Version 2.0 which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
package org.karnak.backend.model.editor; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import org.dcm4che3.data.Attributes; | ||
import org.dcm4che3.data.Tag; | ||
import org.dcm4che3.data.VR; | ||
import org.junit.Assert; | ||
import org.junit.jupiter.api.Test; | ||
import org.karnak.backend.data.entity.SOPClassUIDEntity; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.weasis.dicom.param.AttributeEditorContext; | ||
import org.weasis.dicom.param.AttributeEditorContext.Abort; | ||
import org.weasis.dicom.param.DicomNode; | ||
|
||
@SpringBootTest | ||
class FilterEditorTest { | ||
|
||
@Test | ||
void when_no_class_uid_found_should_modify_context() { | ||
// Init data | ||
// SopClassUIDEntities | ||
Set<SOPClassUIDEntity> sopClassUIDEntities = new HashSet<>(); | ||
SOPClassUIDEntity sopClassUIDEntityFirst = new SOPClassUIDEntity(); | ||
SOPClassUIDEntity sopClassUIDEntitySecond = new SOPClassUIDEntity(); | ||
sopClassUIDEntityFirst.setUid("TEST FIRST"); | ||
sopClassUIDEntitySecond.setUid("TEST SECOND"); | ||
sopClassUIDEntities.add(sopClassUIDEntityFirst); | ||
sopClassUIDEntities.add(sopClassUIDEntitySecond); | ||
|
||
// Attributes | ||
Attributes attributes = new Attributes(); | ||
attributes.setString(Tag.SOPClassUID, VR.SH, "TEST NOT FOUND"); | ||
|
||
// AttributeEditorContext | ||
DicomNode source = new DicomNode("source"); | ||
DicomNode destination = new DicomNode("destination"); | ||
AttributeEditorContext attributeEditorContext = | ||
new AttributeEditorContext("tsuid", source, destination); | ||
|
||
// Create filterEditor | ||
FilterEditor filterEditor = new FilterEditor(sopClassUIDEntities); | ||
|
||
// Call service | ||
filterEditor.apply(attributes, attributeEditorContext); | ||
|
||
// Test results | ||
Assert.assertEquals(Abort.FILE_EXCEPTION, attributeEditorContext.getAbort()); | ||
} | ||
|
||
@Test | ||
void when_class_uid_found_should_not_modify_context() { | ||
// Init data | ||
// SopClassUIDEntities | ||
Set<SOPClassUIDEntity> sopClassUIDEntities = new HashSet<>(); | ||
SOPClassUIDEntity sopClassUIDEntityFirst = new SOPClassUIDEntity(); | ||
SOPClassUIDEntity sopClassUIDEntitySecond = new SOPClassUIDEntity(); | ||
sopClassUIDEntityFirst.setUid("TEST FIRST"); | ||
sopClassUIDEntitySecond.setUid("TEST SECOND"); | ||
sopClassUIDEntities.add(sopClassUIDEntityFirst); | ||
sopClassUIDEntities.add(sopClassUIDEntitySecond); | ||
|
||
// Attributes | ||
Attributes attributes = new Attributes(); | ||
attributes.setString(Tag.SOPClassUID, VR.SH, "TEST FIRST"); | ||
|
||
// AttributeEditorContext | ||
DicomNode source = new DicomNode("source"); | ||
DicomNode destination = new DicomNode("destination"); | ||
AttributeEditorContext attributeEditorContext = | ||
new AttributeEditorContext("tsuid", source, destination); | ||
|
||
// Create filterEditor | ||
FilterEditor filterEditor = new FilterEditor(sopClassUIDEntities); | ||
|
||
// Call service | ||
filterEditor.apply(attributes, attributeEditorContext); | ||
|
||
// Test results | ||
Assert.assertNotEquals(Abort.FILE_EXCEPTION, attributeEditorContext.getAbort()); | ||
} | ||
} |
Oops, something went wrong.