validator/src/test/java/de/kosit/validationtool/impl/ConversionServiceTest.java
Adrian-Devries 2466f9cf5d 25-FixTypos
2025-04-24 12:54:11 +02:00

105 lines
3.4 KiB
Java

/*
* Copyright 2017-2022 Koordinierungsstelle für IT-Standards (KoSIT)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.kosit.validationtool.impl;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
import java.io.Serializable;
import java.net.URL;
import org.junit.Before;
import org.junit.Test;
import de.kosit.validationtool.impl.Helper.Invalid;
import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.model.scenarios.Scenarios;
/**
* Simple test for testing the jaxb conversion service.
*
* @author apenski
*/
public class ConversionServiceTest {
private static final URL SCHEMA = ConversionServiceTest.class.getResource("/xsd/scenarios.xsd");
private ConversionService service;
private ContentRepository repository;
@Before
public void setup() {
this.service = new ConversionService();
this.repository = Simple.createContentRepository();
}
@Test
public void testMarshalNull() {
assertThrows(ConversionService.ConversionException.class, () -> this.service.writeXml(null));
}
@Test
public void testMarshalUnknown() {
assertThrows(ConversionService.ConversionException.class, () -> this.service.writeXml(new Serializable() {
private static final long serialVersionUID = 8745690876369610705L;
}));
}
@Test
public void testUnmarshal() {
final Scenarios s = this.service.readXml(Simple.SCENARIOS, Scenarios.class);
assertThat(s).isNotNull();
assertThat(s.getName()).isEqualToIgnoringCase("HTML-TestSuite");
}
@Test
public void testUnmarshalWithSchema() {
final Scenarios s = this.service.readXml(Simple.SCENARIOS, Scenarios.class, this.repository.createSchema(SCHEMA));
assertThat(s).isNotNull();
assertThat(s.getName()).isEqualToIgnoringCase("HTML-TestSuite");
}
@Test
public void testUnmarshalInvalidXml() {
assertThrows(ConversionService.ConversionException.class,
() -> this.service.readXml(Invalid.SCENARIOS, Scenarios.class, this.repository.createSchema(SCHEMA)));
}
@Test
public void testUnmarshalIllFormed() {
assertThrows(ConversionService.ConversionException.class,
() -> this.service.readXml(Invalid.SCENARIOS_ILL_FORMED, Scenarios.class, this.repository.createSchema(SCHEMA)));
}
@Test
public void testUnmarshalEmpty() {
assertThrows(ConversionService.ConversionException.class, () -> this.service.readXml(null, Scenarios.class));
}
@Test
public void testUnmarshalUnknownType() {
assertThrows(ConversionService.ConversionException.class, () -> this.service.readXml(Simple.SCENARIOS, ConversionService.class));
}
@Test
public void testUnmarshalWithoutType() {
assertThrows(ConversionService.ConversionException.class, () -> this.service.readXml(Simple.SCENARIOS, null));
}
}