Skip to content

Commit

Permalink
Fixes docker build issue with SM Repo (#134)
Browse files Browse the repository at this point in the history
* Fixes docker build issue with SM Repo

Signed-off-by: Mohammad Ghazanfar Ali Danish <[email protected]>

* Adds missing test file

Signed-off-by: Mohammad Ghazanfar Ali Danish <[email protected]>

---------

Signed-off-by: Mohammad Ghazanfar Ali Danish <[email protected]>
  • Loading branch information
mdanish98 authored Nov 13, 2023
1 parent a591764 commit 07a0303
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void deleteFileFromNotExistElement() throws FileNotFoundException, Unsupp

@Test
public void getFile() throws FileNotFoundException, IOException, ParseException {
String fileName = "BaSyx-Logo.png";
String fileName = DummySubmodelFactory.FILE_NAME;

byte[] expectedFile = readBytesFromClasspath(fileName);

Expand Down Expand Up @@ -281,9 +281,9 @@ private String createSMEFileGetURL(String submodelId, String submodelElementIdSh
private CloseableHttpResponse uploadFileToSubmodelElement(String submodelId, String submodelElementIdShort) throws IOException {
CloseableHttpClient client = HttpClients.createDefault();

String fileName = "BaSyx-Logo.png";
String fileName = DummySubmodelFactory.FILE_NAME;

java.io.File file = ResourceUtils.getFile("src/test/resources/" + fileName);
java.io.File file = ResourceUtils.getFile("classpath:" + fileName);

HttpPut putRequest = createPutRequestWithFile(submodelId, submodelElementIdShort, fileName, file);

Expand Down Expand Up @@ -382,7 +382,7 @@ private byte[] readBytesFromClasspath(String fileName) throws FileNotFoundExcept
}

protected List<Submodel> createSubmodels() {
return Arrays.asList(DummySubmodelFactory.createTechnicalDataSubmodel(), DummySubmodelFactory.createOperationalDataSubmodel(), DummySubmodelFactory.createSimpleDataSubmodel());
return Arrays.asList(DummySubmodelFactory.createTechnicalDataSubmodel(), DummySubmodelFactory.createOperationalDataSubmodel(), DummySubmodelFactory.createSimpleDataSubmodel(), DummySubmodelFactory.createSubmodelWithFileElement());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@

package org.eclipse.digitaltwin.basyx.submodelrepository.http;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collection;

import org.eclipse.digitaltwin.aas4j.v3.model.Submodel;
import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo;
import org.eclipse.digitaltwin.basyx.http.serialization.BaSyxHttpTestUtils;
import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand All @@ -46,7 +43,6 @@
*/
public class TestSubmodelRepositorySubmodelHTTP extends SubmodelRepositorySubmodelHTTPTestSuite {
private static final PaginationInfo NO_LIMIT_PAGINATION_INFO = new PaginationInfo(0, null);
private static final String SUBMODEL_JSON = "SingleSubmodel4FileTest.json";
private static ConfigurableApplicationContext appContext;

@BeforeClass
Expand All @@ -65,12 +61,6 @@ public void populateRepository() {
SubmodelRepository repo = appContext.getBean(SubmodelRepository.class);
Collection<Submodel> submodels = createSubmodels();
submodels.forEach(repo::createSubmodel);
try {
createSubmodel4FileTest();
} catch (IOException e) {
System.out.println("Cannot load " + SUBMODEL_JSON + " for testing file-upload feature.");
e.printStackTrace();
}
}

@AfterClass
Expand All @@ -83,10 +73,4 @@ protected String getURL() {
return "http://localhost:8080/submodels";
}

private void createSubmodel4FileTest() throws FileNotFoundException, IOException {
String submodelJSON = BaSyxHttpTestUtils.readJSONStringFromClasspath(SUBMODEL_JSON);

BaSyxSubmodelHttpTestUtils.createSubmodel(getURL(), submodelJSON);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import java.util.stream.Stream;

import org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXSD;
import org.eclipse.digitaltwin.aas4j.v3.model.File;
import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes;
import org.eclipse.digitaltwin.aas4j.v3.model.Property;
import org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTypes;
import org.eclipse.digitaltwin.aas4j.v3.model.Submodel;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement;
Expand Down Expand Up @@ -100,8 +102,10 @@ public class DummySubmodelFactory {

//SUBMODEL_FOR_FILE_TEST
public static final String SUBMODEL_FOR_FILE_TEST = "8A6344BDAB57E184";
public static final String SUBMODEL_FOR_FILE_TEST_ID_SHORT = "FileTests";
public static final String SUBMODEL_ELEMENT_FILE_ID_SHORT = "FileData";
public static final String SUBMODEL_ELEMENT_NON_FILE_ID_SHORT = "NonFileParameter";
public static final String FILE_NAME = "BaSyx-Logo.png";

public static Collection<Submodel> getSubmodels() {
return Arrays.asList(createTechnicalDataSubmodel(), createOperationalDataSubmodel(), createSimpleDataSubmodel());
Expand Down Expand Up @@ -129,6 +133,18 @@ public static Submodel createTechnicalDataSubmodel() {
.submodelElements(SubmodelServiceHelper.getAllSubmodelElements())
.build();
}

public static Submodel createSubmodelWithFileElement() {
return new DefaultSubmodel.Builder().semanticID(new DefaultReference.Builder().keys(new DefaultKey.Builder().type(KeyTypes.GLOBAL_REFERENCE)
.value(SUBMODEL_TECHNICAL_DATA_SEMANTIC_ID)
.build())
.type(ReferenceTypes.EXTERNAL_REFERENCE)
.build())
.idShort(SUBMODEL_FOR_FILE_TEST_ID_SHORT)
.id(SUBMODEL_FOR_FILE_TEST)
.submodelElements(Arrays.asList(createFileElement(), createNonFileElement()))
.build();
}

public static Submodel createOperationalDataSubmodel() {
return new DefaultSubmodel.Builder().idShort(SUBMODEL_OPERATIONAL_DATA_ID_SHORT)
Expand Down Expand Up @@ -254,5 +270,19 @@ private static List<SubmodelElement> createSimpleSubmodelElements() {
list.add(createProperty(SUBMODEL_ELEMENT_SIMPLE_DATA_ID_SHORT));
return list;
}

private static Property createNonFileElement() {
Property simpleProperty = SubmodelServiceHelper.createPropertySubmodelElement();
simpleProperty.setIdShort(SUBMODEL_ELEMENT_NON_FILE_ID_SHORT);

return simpleProperty;
}

private static File createFileElement() {
File simpleFile = SubmodelServiceHelper.createFileSubmodelElement();
simpleFile.setValue(FILE_NAME);

return simpleFile;
}

}

0 comments on commit 07a0303

Please sign in to comment.