Skip to content
Snippets Groups Projects
Commit 36d99481 authored by Jan Zickermann's avatar Jan Zickermann
Browse files

Merge branch...

Merge branch 'refs/heads/OZG-5413-Senden-OD-Mantelantrag-an-AFM-Eingangsstelle-via-NB' into OZG-5415-Semantik-Adapter-Formbase

# Conflicts:
#	xta-adapter/src/test/java/de/ozgcloud/eingang/xta/XtaITCase.java
parents 88a2b0ac 56de4e3d
Branches
Tags
No related merge requests found
......@@ -25,6 +25,7 @@ package de.ozgcloud.eingang.common.zip;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
......@@ -42,6 +43,7 @@ import java.util.zip.ZipInputStream;
import org.springframework.util.MimeTypeUtils;
import de.ozgcloud.eingang.common.errorhandling.TechnicalException;
import de.ozgcloud.eingang.common.formdata.DeleteOnCloseInputStream;
import de.ozgcloud.eingang.common.formdata.IncomingFile;
import lombok.Getter;
import lombok.extern.log4j.Log4j2;
......@@ -212,10 +214,27 @@ public class ZipAttachmentReader {
.build();
}
@Deprecated
public InputStream getSourceZipAsStream() {
try {
return new DeleteOnCloseInputStream(sourceZipFile);
} catch (FileNotFoundException e) {
throw new TechnicalException("Original ZIP was deleted", e);
}
}
public File getSourceZip() {
return sourceZipFile;
}
public long getSourceFileSize() {
try {
return Files.size(sourceZipFile.toPath());
} catch (IOException e) {
throw new TechnicalException("Cannot get size of source ZIP.", e);
}
}
String getContentType(String name) {
Objects.requireNonNull(name);
return Objects.requireNonNullElse(URLConnection.guessContentTypeFromName(name), MimeTypeUtils.APPLICATION_OCTET_STREAM_VALUE);
......
......@@ -33,7 +33,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;
import java.util.zip.ZipException;
import java.util.zip.ZipInputStream;
......@@ -47,7 +46,6 @@ import org.mockito.Spy;
import org.springframework.util.MimeTypeUtils;
import de.ozgcloud.common.test.TestUtils;
import de.ozgcloud.eingang.common.formdata.DeleteOnCloseInputStream;
import de.ozgcloud.eingang.common.formdata.IncomingFile;
import lombok.SneakyThrows;
......@@ -75,11 +73,20 @@ class ZipAttachmentReaderTest {
@SneakyThrows
private void verifySourceFileSavedInTmpDirectory() {
try (Stream<Path> paths = Files.find(Path.of(getTmpDirectoryPath()), 1,
((path, basicFileAttributes) -> path.getFileName().toString().startsWith(ZipAttachmentReader.SOURCE_ZIP_PREFIX)))) {
List<Path> foundFiles = paths.toList();
assertThat(foundFiles).hasSize(1);
List<Path> foundFiles = Files.find(Path.of(getTmpDirectoryPath()), 1,
((path, basicFileAttributes) -> path.getFileName().toString().startsWith(ZipAttachmentReader.SOURCE_ZIP_PREFIX)))
.toList();
assertThat(foundFiles).hasSize(1).first();
}
@Test
@DisplayName("should return readable input stream for source zip file")
void shouldReturnSourceStream() {
var expectedContent = TestUtils.loadFile(ZIP_1_FILE_NAME);
var sourceZipAsStream = createZipAttachment(ZIP_1_FILE_NAME).getSourceZipAsStream();
assertThat(sourceZipAsStream).hasSameContentAs(expectedContent);
}
@Test
......@@ -128,7 +135,7 @@ class ZipAttachmentReaderTest {
var attachmentContentList = new ZipAttachmentReader().readContent(loadZip(ZIP_1_FILE_NAME));
assertThat(attachmentContentList).hasSize(1);
var contentEntry = attachmentContentList.getFirst();
var contentEntry = attachmentContentList.get(0);
assertThat(contentEntry.getName()).isEqualTo(content_file_0_name);
assertThat(contentEntry.getSize()).isEqualTo(content_file_0_size);
assertThat(contentEntry.getContentStream()).hasSameContentAs(TestUtils.loadFile(content_file_0_name));
......@@ -162,7 +169,6 @@ class ZipAttachmentReaderTest {
entry.getContentStreamForFinalRead().close();
}
@SneakyThrows
@Test
@DisplayName("should return readable input stream for source zip if cannot extract content")
void shouldReturnSourceStreamByError() {
......@@ -171,7 +177,7 @@ class ZipAttachmentReaderTest {
assertThrows(ReadZipException.class, attachment::readContent);
assertThat(new DeleteOnCloseInputStream(attachment.getSourceZip())).hasSameContentAs(new ByteArrayInputStream(attachmentContent));
assertThat(attachment.getSourceZipAsStream()).hasSameContentAs(new ByteArrayInputStream(attachmentContent));
}
@Test
......@@ -204,37 +210,32 @@ class ZipAttachmentReaderTest {
private static final String ZIP_BOMB_WITH_MANY_FILES = "zipbombs/filewithmanyfiles.dat.zip";
@Test
@SneakyThrows
void shouldFailOnExtremCompressionRatio() {
try (var zip = loadZip(ZIP_BOMB_WITH_BIG_NULL_FILE_CONTENT)) {
var zip = loadZip(ZIP_BOMB_WITH_BIG_NULL_FILE_CONTENT);
ReadZipException exception = assertThrows(ReadZipException.class, () -> reader.readContent(zip));
assertThat(exception.getMessage()).contains("Ratio between compressed and uncompressed data is highly suspicious");
}
}
@Test
@SneakyThrows
void shouldFailOnTotalExtractedSize() {
try (var zip = loadZip(ZIP_1_FILE_NAME)) {
var zip = loadZip(ZIP_1_FILE_NAME);
reader.readContent(zip);
verify(reader).checkTotalExtractedSize(157);
}
}
@Test
@SneakyThrows
void shouldFailOnTotalZipEntries() {
try (var zip = loadZip(ZIP_BOMB_WITH_MANY_FILES)) {
var zip = loadZip(ZIP_BOMB_WITH_MANY_FILES);
ReadZipException exception = assertThrows(ReadZipException.class, () -> reader.readContent(zip));
assertThat(exception.getMessage()).contains("Total entries in zip file exceeded");
}
}
}
@Nested
class TestSaveFiles {
......@@ -299,16 +300,12 @@ class ZipAttachmentReaderTest {
@SneakyThrows
private static void cleanupTempFiles() {
try (Stream<Path> paths = Files.walk(Path.of(TMP_DIRECTORY_PATH), 1)) {
paths.filter(hasNameSuffix).map(Path::toFile).forEach(File::delete);
}
Files.walk(Path.of(TMP_DIRECTORY_PATH), 1).filter(hasNameSuffix).map(Path::toFile).forEach(File::delete);
}
@SneakyThrows
private static boolean noFilesWithSuffixInTempDirectory() {
try (Stream<Path> paths = Files.walk(Path.of(TMP_DIRECTORY_PATH), 1)) {
return paths.noneMatch(hasNameSuffix);
}
return Files.walk(Path.of(TMP_DIRECTORY_PATH), 1).noneMatch(hasNameSuffix);
}
@SneakyThrows
......
......@@ -25,13 +25,6 @@ public class XdomeaXMLValueReader {
private static final String DATEINAME_NODE_QUERY_STRING = "//Hauptobjekt//Dateiname";
private static final XPathExpression DATEINAME_NODE_QUERY = compileXPathExpression(DATEINAME_NODE_QUERY_STRING);
/**
* Find all 'Dateiname' elements in the 'Hauptobjekt' element.
* <h4>Struktur</h4> Geschaeftsgang.Geschaeftsgang.0201 > Hauptobjekt > Dokument > Version > Format > Primaerdokument > Dateiname
*
* @param xdomeaXMLFile the xml incoming file of a xdomea Geschaeftsvorgang.Geschaeftsvorgang.0201
* @return list of file names which represent the primary document
*/
public List<String> readRepresentationFileNames(IncomingFile xdomeaXMLFile) {
return getTextsFromNodes(
queryDateinameNodeList(
......
......@@ -11,7 +11,7 @@ import java.security.cert.CertificateException;
import javax.net.ssl.KeyManagerFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.webservices.client.WebServiceTemplateCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -28,12 +28,12 @@ import lombok.extern.log4j.Log4j2;
@Log4j2
@Configuration
@RequiredArgsConstructor
public class XtaRemoteServiceConfiguration {
static final String URI_TEMPLATE = "%s://%s/MB_XTA-WS/XTA210msgBoxPort.svc";
private final XtaProperties properties;
@Autowired
private XtaProperties properties;
@Bean
Jaxb2Marshaller osciTransportMarshaller() {
......
package de.ozgcloud.eingang.xta;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Profile;
import org.springframework.context.event.ContextRefreshedEvent;
......@@ -11,15 +11,15 @@ import de.ozgcloud.eingang.semantik.SemantikAdapter;
import lombok.NonNull;
import lombok.extern.log4j.Log4j2;
@Profile("!itcase")
@Log4j2
@Component
@RequiredArgsConstructor
class XtaRunner implements ApplicationListener<ContextRefreshedEvent> {
private final XtaService service;
private final SemantikAdapter semantikAdapter;
@Autowired
private XtaService service;
@Autowired
private SemantikAdapter semantikAdapter;
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
......
package de.ozgcloud.eingang.xta;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
......@@ -14,7 +15,7 @@ class XtaApplicationTest {
@Test
void startup() {
// should start without exception;
Assertions.assertTrue(true);
assertTrue(true);
}
}
......@@ -59,7 +59,6 @@ class XtaServiceITCase {
void shouldUnzipCorrectNumberOfRepresentations() {
var firstFormData = xtaService.getMessages().toList().getFirst();
// Expect that there are 3 files (xdomea.xml, intelliform.xml and intelliform.pdf)
assertThat(firstFormData.getRepresentations()).hasSize(3);
assertThat(firstFormData.getNumberOfRepresentations()).isEqualTo(3);
}
......@@ -69,7 +68,6 @@ class XtaServiceITCase {
void shouldUnzipCorrectNumberOfAttachments() {
var firstFormData = xtaService.getMessages().toList().getFirst();
// Expect that there are no attachment files
assertThat(firstFormData.getAttachments()).isEmpty();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment