1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */1718package org.apache.any23.vocab;
1920import org.apache.any23.util.StringUtils;
21import org.junit.Assert;
22import org.junit.Test;
23import org.eclipse.rdf4j.rio.RDFFormat;
24import org.slf4j.Logger;
25import org.slf4j.LoggerFactory;
2627import java.io.ByteArrayOutputStream;
28import java.io.PrintStream;
29import java.nio.charset.StandardCharsets;
3031/**32 * Test case for {@link RDFSchemaUtils}.33 *34 * @author Michele Mostarda (mostarda@fbk.eu)35 */36publicclassRDFSchemaUtilsTest {
3738privatestaticfinal Logger logger = LoggerFactory.getLogger(RDFSchemaUtilsTest.class);
3940/**41 * Test case for {@link RDFSchemaUtils#serializeVocabularies( org.eclipse.rdf4j.rio.RDFFormat, java.io.PrintStream)}42 * with <i>NTriples</i> format.43 */44 @Test
45publicvoid testSerializeVocabulariesNTriples() {
46 serializeVocabularies(RDFFormat.NTRIPLES, 2178);
47 }
4849/**50 * Test case for {@link RDFSchemaUtils#serializeVocabularies( org.eclipse.rdf4j.rio.RDFFormat, java.io.PrintStream)}51 * with <i>RDFXML</i> format.52 */53 @Test
54publicvoid testSerializeVocabulariesRDFXML() {
55 serializeVocabularies(RDFFormat.RDFXML, 5709); // Effective lines + separators.56 }
5758privatevoid serializeVocabularies(RDFFormat format, int expectedLines) {
59final ByteArrayOutputStream baos = new ByteArrayOutputStream();
60try (PrintStream ps = new PrintStream(baos, true, StandardCharsets.UTF_8)) {
61 RDFSchemaUtils.serializeVocabularies(format, ps);
62 }
63final String output = baos.toString(StandardCharsets.UTF_8);
64 logger.debug(output);
65finalint occurrences = StringUtils.countOccurrences(output, "\n");
66 Assert.assertEquals(expectedLines, occurrences);
67 }
6869 }