-
Notifications
You must be signed in to change notification settings - Fork 48
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
Implements InMemory AASX file server #84
Changes from 1 commit
22dc8a8
6893942
fa1b16d
35db5d6
54b33f3
bf03b58
393d5be
859ab7a
7c63c47
d1f74e9
b0840da
dd949ef
4fccd79
6fb98ac
1d1052c
4a636e9
f0169fc
50a55b1
e4f1934
fa5272f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The createAASXPackage test is missing, please add it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added the test case |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,12 +35,12 @@ | |
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Iterator; | ||
import org.apache.commons.io.IOUtils; | ||
|
||
import org.eclipse.digitaltwin.basyx.aasxfileserver.AASXFileServer; | ||
import org.eclipse.digitaltwin.basyx.aasxfileserver.PackageDescription; | ||
import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; | ||
import org.junit.Test; | ||
import org.eclipse.digitaltwin.basyx.aasxfileserver.core.DummyAASXFileServerFactory; | ||
|
||
/** | ||
* Testsuite for implementations of the {@link AASXFileServer} interface | ||
|
@@ -49,134 +49,122 @@ | |
* | ||
*/ | ||
public abstract class AASXFileServerSuite { | ||
protected abstract AASXFileServer getAASXFileServer(); | ||
|
||
protected abstract AASXFileServer getAASXFileServer(); | ||
|
||
@Test | ||
public void getAllAASXPackageIds() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a test case for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a test case. |
||
AASXFileServer server = getAASXFileServer(); | ||
Collection<PackageDescription> packageDescriptions = DummyAASXFileServerFactory.getAllDummyAASXPackages(server); | ||
|
||
AASXFileServer server = getAASXFileServer(); | ||
Collection<PackageDescription> packageDescriptions = DummyAASXFileServerFactory.getAllDummyAASXPackages(server); | ||
|
||
assertGetAllAASXPackageIds(packageDescriptions); | ||
} | ||
|
||
@Test | ||
public void getAllAASXPackageIdsEmpty() { | ||
AASXFileServer server = getAASXFileServer(); | ||
Collection<PackageDescription> packageDescriptions = server.getAllAASXPackageIds(); | ||
assertIsEmpty(packageDescriptions); | ||
|
||
AASXFileServer server = getAASXFileServer(); | ||
Collection<PackageDescription> packageDescriptions = server.getAllAASXPackageIds(); | ||
|
||
assertTrue(packageDescriptions.isEmpty()); | ||
} | ||
|
||
@Test(expected = ElementDoesNotExistException.class) | ||
public void getSpecificNonExistingPackageId() { | ||
|
||
AASXFileServer server = getAASXFileServer(); | ||
server.getAASXByPackageId("doesNotExist"); | ||
} | ||
|
||
@Test | ||
public void updateExistingAASXByPackageId() { | ||
AASXFileServer server = getAASXFileServer(); | ||
PackageDescription expectedPackageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); | ||
updateAasxPackage(server, expectedPackageDescription.getPackageId(), DummyAASXFileServerFactory.SECOND_AAS_IDS , | ||
DummyAASXFileServerFactory.SECOND_FILE, DummyAASXFileServerFactory.SECOND_FILENAME); | ||
public void updateExistingAASXByPackageId() { | ||
|
||
AASXFileServer server = getAASXFileServer(); | ||
|
||
PackageDescription expectedPackageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); | ||
|
||
updateAasxPackage(server, expectedPackageDescription.getPackageId(), DummyAASXFileServerFactory.SECOND_AAS_IDS, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Last two parameters are not required, please remove them and update the method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
DummyAASXFileServerFactory.SECOND_FILE, DummyAASXFileServerFactory.SECOND_FILENAME); | ||
|
||
Collection<PackageDescription> actualPackageDescription = server.getAllAASXPackageIds(); | ||
|
||
assertUpdatedAASXPackageId(expectedPackageDescription, actualPackageDescription, server); | ||
} | ||
} | ||
|
||
@Test(expected = ElementDoesNotExistException.class) | ||
public void updateNonExistingAASXByPackageId() { | ||
|
||
String packageId = "notExisting"; | ||
|
||
String packageId = "notExisting"; | ||
AASXFileServer server = getAASXFileServer(); | ||
server.updateAASXByPackageId(packageId, DummyAASXFileServerFactory.FIRST_AAS_IDS, | ||
DummyAASXFileServerFactory.FIRST_FILE, DummyAASXFileServerFactory.FIRST_FILENAME); | ||
} | ||
|
||
AASXFileServer server = getAASXFileServer(); | ||
|
||
server.updateAASXByPackageId(packageId, DummyAASXFileServerFactory.FIRST_AAS_IDS, DummyAASXFileServerFactory.FIRST_FILE, DummyAASXFileServerFactory.FIRST_FILENAME); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please utilize the method for this purpose (updateAasxPackage) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
|
||
@Test | ||
public void getAASXByPackageId() throws ElementDoesNotExistException, IOException { | ||
|
||
AASXFileServer server = getAASXFileServer(); | ||
PackageDescription packageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); | ||
InputStream actualValue = server.getAASXByPackageId(packageDescription.getPackageId()); | ||
InputStream expectedValue = DummyAASXFileServerFactory.FIRST_FILE; | ||
|
||
assertInputStreamsEqual(expectedValue, actualValue); | ||
|
||
PackageDescription packageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); | ||
|
||
InputStream actualValue = server.getAASXByPackageId(packageDescription.getPackageId()); | ||
InputStream expectedValue = DummyAASXFileServerFactory.FIRST_FILE; | ||
|
||
assertTrue(IOUtils.contentEquals(expectedValue, actualValue)); | ||
} | ||
|
||
@Test | ||
public void deleteAASXByPackageId() { | ||
|
||
AASXFileServer server = getAASXFileServer(); | ||
PackageDescription packageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); | ||
server.deleteAASXByPackageId(packageDescription.getPackageId()); | ||
|
||
PackageDescription packageDescription = DummyAASXFileServerFactory.createFirstDummyAASXPackage(server); | ||
|
||
server.deleteAASXByPackageId(packageDescription.getPackageId()); | ||
|
||
try { | ||
server.getAASXByPackageId(packageDescription.getPackageId()); | ||
fail(); | ||
} catch (ElementDoesNotExistException expected) { | ||
} | ||
} | ||
} | ||
|
||
@Test(expected = ElementDoesNotExistException.class) | ||
public void deleteNonExistingAasxFileServer() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Name of this method is not correct. Please correct it (suggestion: deleteNonExistingAASX) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
AASXFileServer server = getAASXFileServer(); | ||
server.deleteAASXByPackageId("nonExisting"); | ||
} | ||
|
||
private void updateAasxPackage(AASXFileServer server, String packageId, List<String> expectedAasIds, InputStream secondFile, | ||
String secondFilename) { | ||
|
||
server.updateAASXByPackageId(packageId, expectedAasIds, | ||
DummyAASXFileServerFactory.SECOND_FILE, DummyAASXFileServerFactory.SECOND_FILENAME); | ||
|
||
} | ||
|
||
private void assertGetAllAASXPackageIds(Collection<PackageDescription> packageDescriptions) { | ||
assertEquals(2, packageDescriptions.size()); | ||
|
||
Iterator<PackageDescription> iterator = packageDescriptions.iterator(); | ||
|
||
PackageDescription expectedFirstPackage = iterator.next(); | ||
PackageDescription expectedSecondPackage = iterator.next(); | ||
|
||
assertTrue(packageDescriptions.containsAll(Arrays.asList(expectedFirstPackage, expectedSecondPackage))); | ||
} | ||
|
||
private void assertUpdatedAASXPackageId(PackageDescription expectedPackageDescription, Collection<PackageDescription> actualPackageDescriptions, AASXFileServer server) { | ||
assertEquals(1, actualPackageDescriptions.size()); | ||
assertTrue(actualPackageDescriptions.contains(expectedPackageDescription)); | ||
|
||
InputStream actualAASXFile = server.getAASXByPackageId("1"); | ||
InputStream expectedAASXFile = DummyAASXFileServerFactory.SECOND_FILE; | ||
|
||
assertEquals(expectedAASXFile,actualAASXFile); | ||
|
||
private void updateAasxPackage(AASXFileServer server, String packageId, List<String> expectedAasIds, | ||
InputStream secondFile, String secondFilename) { | ||
|
||
server.updateAASXByPackageId(packageId, expectedAasIds, DummyAASXFileServerFactory.SECOND_FILE, DummyAASXFileServerFactory.SECOND_FILENAME); | ||
} | ||
|
||
private void assertIsEmpty(Collection<PackageDescription> packageDescription) { | ||
assertTrue(packageDescription.isEmpty()); | ||
} | ||
|
||
private boolean assertInputStreamsEqual(InputStream expectedValue, InputStream actualValue) throws IOException { | ||
int expectedByte; | ||
int actualByte; | ||
|
||
while ((expectedByte = expectedValue.read()) != -1) { | ||
actualByte = actualValue.read(); | ||
|
||
if (expectedByte != actualByte) { | ||
return false; | ||
} | ||
} | ||
return actualValue.read() == -1; | ||
|
||
private void assertGetAllAASXPackageIds(Collection<PackageDescription> packageDescriptions) { | ||
assertEquals(2, packageDescriptions.size()); | ||
|
||
Iterator<PackageDescription> iterator = packageDescriptions.iterator(); | ||
|
||
PackageDescription expectedFirstPackage = iterator.next(); | ||
PackageDescription expectedSecondPackage = iterator.next(); | ||
|
||
assertTrue(packageDescriptions.containsAll(Arrays.asList(expectedFirstPackage, expectedSecondPackage))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong, actual is same as the expected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changes done |
||
} | ||
|
||
private void assertUpdatedAASXPackageId(PackageDescription expectedPackageDescription, | ||
Collection<PackageDescription> actualPackageDescriptions, AASXFileServer server) { | ||
|
||
assertEquals(1, actualPackageDescriptions.size()); | ||
assertTrue(actualPackageDescriptions.contains(expectedPackageDescription)); | ||
|
||
InputStream actualAASXFile = server.getAASXByPackageId("1"); | ||
InputStream expectedAASXFile = DummyAASXFileServerFactory.SECOND_FILE; | ||
|
||
assertEquals(expectedAASXFile, actualAASXFile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use IOUtils to compare the content of the IS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As identifier is generated automatically at runtime, there is no chance of collision.
Please remove this throws declaration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done