com.fasterxml.jackson.dataformat.yaml.YAMLFactory Java Examples

The following examples show how to use com.fasterxml.jackson.dataformat.yaml.YAMLFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReplicaStoreTest.java    From pegasus with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultipleReplicas() throws IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false);

    String test =
            "pegasus: \"5.0\"\n"
                    + "replicas:\n"
                    + "  # matches \"f.a\"\n"
                    + "  - lfn: \"f.a\"\n"
                    + "    pfns:\n"
                    + "      - pfn: \"file:///Volumes/data/input/f.a\"\n"
                    + "        site: \"local\"\n"
                    + "  # matches \"f.b\"\n"
                    + "  - lfn: \"f.b\"\n"
                    + "    pfns:\n"
                    + "      - pfn: \"file:///Volumes/data/input/f.b\"\n"
                    + "        site: \"isi\"";

    ReplicaStore store = mapper.readValue(test, ReplicaStore.class);
    assertNotNull(store);
    assertEquals(2, store.getLFNCount());
    testBasicReplicaLocation(
            store.get("f.a"), "f.a", "file:///Volumes/data/input/f.a", "local");
    testBasicReplicaLocation(store.get("f.b"), "f.b", "file:///Volumes/data/input/f.b", "isi");
}
 
Example #2
Source File: DefaultConfigurationTest.java    From elasticactors with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoadDefaultConfig() throws IOException {
    File configFile = ResourceUtils.getFile("classpath:ea-default.yaml");
    // get the yaml resource

    // yaml mapper
    ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
    DefaultConfiguration configuration = objectMapper.readValue(new FileInputStream(configFile), DefaultConfiguration.class);

    assertEquals(configuration.getName(),"default");
    assertEquals(configuration.getNumberOfShards(),8);
    assertNotNull(configuration.getRemoteConfigurations());
    assertFalse(configuration.getRemoteConfigurations().isEmpty());
    assertEquals(configuration.getRemoteConfigurations().size(),2);
    assertEquals(configuration.getRemoteConfigurations().get(0).getClusterName(),"test2.elasticsoftware.org");
    assertEquals(configuration.getRemoteConfigurations().get(1).getClusterName(),"test3.elasticsoftware.org");
    //assertEquals(configuration.getProperty(HttpService.class, "listenPort", Integer.class, 9090),new Integer(8080));
}
 
Example #3
Source File: JobTest.java    From pegasus with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleJobCreation() throws IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false);

    String test =
            "id: ID000001\n"
                    + "name: preprocess\n"
                    + "namespace: diamond\n"
                    + "version: \"2.0\"";

    Job job = mapper.readValue(test, Job.class);
    assertNotNull(job);
    assertEquals("ID000001", job.getLogicalID());
    assertEquals("preprocess", job.getTXName());
    assertEquals("diamond", job.getTXNamespace());
    assertEquals("2.0", job.getTXVersion());
}
 
Example #4
Source File: ProfileValidateRequestExecutor.java    From kubernetes-elastic-agents with Apache License 2.0 6 votes vote down vote up
private void validatePodYaml(HashMap<String, String> properties, ArrayList<Map<String, String>> result) {
    String key = POD_CONFIGURATION.getKey();
    String podYaml = properties.get(key);
    if (StringUtils.isBlank(podYaml)) {
        addNotBlankError(result, key, "Pod Configuration");
        return;
    }
    Pod pod = new Pod();
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    try {
        pod = mapper.readValue(KubernetesInstanceFactory.getTemplatizedPodSpec(podYaml), Pod.class);
    } catch (IOException e) {
        addError(result, key, "Invalid Pod Yaml.");
        return;
    }

    if (StringUtils.isNotBlank(pod.getMetadata().getGenerateName())) {
        addError(result, key, "Invalid Pod Yaml. generateName field is not supported by GoCD. Please use {{ POD_POSTFIX }} instead.");
    }
}
 
Example #5
Source File: ValidatorTest.java    From validator-badge with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidateInvalid20SpecByContent() throws Exception {
    final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    final JsonNode rootNode = mapper.readTree(Files.readAllBytes(java.nio.file.Paths.get(getClass().getResource(INVALID_20_YAML).toURI())));
    ValidatorController validator = new ValidatorController();
    ResponseContext response = validator.validateByContent(new RequestContext(), rootNode);

    Assert.assertEquals(IMAGE, response.getContentType().getType());
    Assert.assertEquals(PNG, response.getContentType().getSubtype());
    InputStream entity = (InputStream)response.getEntity();
    InputStream valid = this.getClass().getClassLoader().getResourceAsStream(INVALID_IMAGE);

    Assert.assertTrue( validateEquals(entity,valid) == true);


}
 
Example #6
Source File: JobTest.java    From pegasus with Apache License 2.0 6 votes vote down vote up
@Test(expected = RuntimeException.class)
public void testDAGJobWihtoutFile() throws IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false);

    String test =
            "type: condorWorkflow\n"
                    + "id: ID000002\n"
                    + "uses:\n"
                    + "  - lfn: finalization.dag\n"
                    + "    type: input\n"
                    + "    stageOut: True\n"
                    + "    registerReplica: False";

    DAGJob job = (DAGJob) mapper.readValue(test, Job.class);
}
 
Example #7
Source File: ArchiveFactory.java    From phantomjs-maven-plugin with MIT License 6 votes vote down vote up
public Archive create(String version) {

    OperatingSystem operatingSystem = this.operatingSystemFactory.create();

    Archive archive = null;

    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    URL resource = ArchiveFactory.class.getResource("/archive-mapping.yaml");
    try {
      ArchiveMappings archiveMappings = mapper.readValue(resource, ArchiveMappings.class);
      for (ArchiveMapping archiveMapping : archiveMappings.getMappings()) {
        if (archiveMapping.getSpec().matches(version, operatingSystem)) {
          archive = new TemplatedArchive(archiveMapping.getFormat(), version);
          break;
        }
      }
    } catch (IOException e) {
      LOGGER.error("Unable to read archive-mapping.yaml", e);
    }
    if (archive == null) {
      throw new UnsupportedPlatformException(operatingSystem);
    }
    return archive;
  }
 
Example #8
Source File: DependencyEnricher.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private void processArtifactSetResources(Set<URL> artifactSet, Function<List<HasMetadata>, Void> function) {
    for (URL url : artifactSet) {
        try {
            log.debug("Processing Kubernetes YAML in at: %s", url);
            KubernetesList resources = new ObjectMapper(new YAMLFactory()).readValue(url, KubernetesList.class);
            List<HasMetadata> items = resources.getItems();
            if (items.isEmpty() && Objects.equals("Template", resources.getKind())) {
                Template template = new ObjectMapper(new YAMLFactory()).readValue(url, Template.class);
                if (template != null) {
                    items.add(template);
                }
            }
            for (HasMetadata item : items) {
                KubernetesResourceUtil.setSourceUrlAnnotationIfNotSet(item, url.toString());
                log.debug("  found %s  %s", KubernetesHelper.getKind(item), KubernetesHelper.getName(item));
            }
            function.apply(items);
        } catch (IOException e) {
            getLog().debug("Skipping %s: %s", url, e);
        }
    }
}
 
Example #9
Source File: SpinalTapStandaloneApp.java    From SpinalTap with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  if (args.length != 1) {
    log.error("Usage: SpinalTapStandaloneApp <config.yaml>");
    System.exit(1);
  }

  final ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
  final SpinalTapStandaloneConfiguration config =
      objectMapper.readValue(new File(args[0]), SpinalTapStandaloneConfiguration.class);

  final MysqlPipeFactory mysqlPipeFactory = createMysqlPipeFactory(config);
  final ZookeeperRepositoryFactory zkRepositoryFactory = createZookeeperRepositoryFactory(config);
  final PipeManager pipeManager = new PipeManager();

  for (MysqlConfiguration mysqlSourceConfig : config.getMysqlSources()) {
    final String sourceName = mysqlSourceConfig.getName();
    final String partitionName = String.format("%s_0", sourceName);
    pipeManager.addPipes(
        sourceName,
        partitionName,
        mysqlPipeFactory.createPipes(mysqlSourceConfig, partitionName, zkRepositoryFactory, 0));
  }

  Runtime.getRuntime().addShutdownHook(new Thread(pipeManager::stop));
}
 
Example #10
Source File: GridGateway.java    From pegasus with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false);

    String test =
            "type: gt5\n"
                    + "contact: smarty.isi.edu/jobmanager-pbs\n"
                    + "scheduler: pbs\n"
                    + "jobtype: auxillary";
    try {
        GridGateway gateway = mapper.readValue(test, GridGateway.class);
        System.out.println(gateway);
        System.out.println(mapper.writeValueAsString(gateway));
    } catch (IOException ex) {
        Logger.getLogger(GridGateway.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example #11
Source File: MetadataTest.java    From pegasus with Apache License 2.0 6 votes vote down vote up
@Test
public void serializationWithNoMetadata() throws IOException {
    ObjectMapper mapper =
            new ObjectMapper(
                    new YAMLFactory().configure(YAMLGenerator.Feature.INDENT_ARRAYS, true));
    mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false);

    // metadata serialization can only be tested by being enclosed in a ReplicaLocation
    // object as we don't have writeStartObject in the serializer implementatio of Metadata
    ReplicaLocation rl = new ReplicaLocation();
    rl.setLFN("test");

    String expected = "---\n" + "lfn: \"test\"\n";

    String actual = mapper.writeValueAsString(rl);

    assertEquals(expected, actual);
}
 
Example #12
Source File: ValidatorTest.java    From validator-badge with Apache License 2.0 6 votes vote down vote up
@Test
    public void testDebugInvalid20SpecByContent() throws Exception {
        final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        final JsonNode rootNode = mapper.readTree(Files.readAllBytes(java.nio.file.Paths.get(getClass().getResource(INVALID_20_YAML).toURI())));
        ValidatorController validator = new ValidatorController();
        ResponseContext response = validator.reviewByContent(new RequestContext(), rootNode);

        // since inflector 2.0.3 content type is managed by inflector according to request headers and spec
/*
        Assert.assertEquals(APPLICATION, response.getContentType().getType());
        Assert.assertEquals(JSON, response.getContentType().getSubtype());
*/
        ValidationResponse validationResponse = (ValidationResponse) response.getEntity();
        Assert.assertTrue(validationResponse.getMessages().contains(INFO_MISSING));
        Assert.assertTrue(validationResponse.getSchemaValidationMessages().get(0).getMessage().equals(INFO_MISSING_SCHEMA));
    }
 
Example #13
Source File: MetadataTest.java    From pegasus with Apache License 2.0 5 votes vote down vote up
@Test
public void serializationWithOnlyMetadata() throws IOException {
    ObjectMapper mapper =
            new ObjectMapper(
                    new YAMLFactory().configure(YAMLGenerator.Feature.INDENT_ARRAYS, true));
    mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false);

    // metadata serialization can only be tested by being enclosed in a ReplicaLocation
    // object as we don't have writeStartObject in the serializer implementatio of Metadata
    ReplicaLocation rl = new ReplicaLocation();
    rl.setLFN("test");

    Metadata m = new Metadata();
    rl.addMetadata("user", "vahi");
    rl.addMetadata("year", "2020");

    String expected =
            "---\n"
                    + "lfn: \"test\"\n"
                    + "metadata:\n"
                    + "  year: \"2020\"\n"
                    + "  user: \"vahi\"\n";

    String actual = mapper.writeValueAsString(rl);

    assertEquals(expected, actual);
}
 
Example #14
Source File: KafkaConfigTest.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Test
public void ensureKafkaDefaultConfigDeserialization()
    throws IOException, URISyntaxException, ConfigurationException {
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ObjectMapper mapper = CustomJsonObjectMapperFactory.build(new YAMLFactory());
    ConfigurationFactory configurationFactory = new ConfigurationFactory(KafkaConfiguration.class, validator, mapper, "dw");
    // Make sure that our config files are up to date
    configurationFactory.build(
        new File(KafkaConfiguration.class.getResource("/emodb-kafka-config.yaml").toURI()));
}
 
Example #15
Source File: LoaderModule.java    From Image-Cipher with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@Named("YamlMapper")
public ObjectMapper provideYamlMapper() {
  ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  mapper.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, true);
  return mapper;
}
 
Example #16
Source File: Util.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
/**
 * <p>Converts a given yamlString into a JsonString.</p>
 * <p>Example Usage:</p>
 * <pre>{@code
 * String jsonString = convertToJson(yourYamlString);}
 * </pre>
 * @param yamlString the yaml to convert
 * @return the json conversion of the yaml string.
 */
public static String convertToJson(String yamlString) {
    try {
        ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
        Object obj = yamlReader.readValue(yamlString, Object.class);

        ObjectMapper jsonWriter = new ObjectMapper();
        return jsonWriter.writeValueAsString(obj);
    } catch (JsonProcessingException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #17
Source File: KubernetesElasticAgent.java    From kubernetes-elastic-agents with Apache License 2.0 5 votes vote down vote up
private static String getPodConfiguration(Pod pod) {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

    try {
        return mapper.writeValueAsString(pod);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
        return "Failed to get Pod Configuration!";
    }
}
 
Example #18
Source File: NodePathTest.java    From styx with Apache License 2.0 5 votes vote down vote up
private static JsonNode parseYaml(String yaml) {
    try {
        return new ObjectMapper(new YAMLFactory()).readTree(yaml);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #19
Source File: CommonUtil.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a YAML file into JSON.
 *
 * @param yaml yaml representation
 * @return yaml file as a json
 * @throws IOException If an error occurs while converting YAML to JSON
 */
public static String yamlToJson(String yaml) throws IOException {

    ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
    Object obj = yamlReader.readValue(yaml, Object.class);

    ObjectMapper jsonWriter = new ObjectMapper();
    return jsonWriter.writeValueAsString(obj);
}
 
Example #20
Source File: YAML.java    From pegasus with Apache License 2.0 5 votes vote down vote up
/**
 * Reads the on-disk map file into memory.
 *
 * @param filename is the name of the file to read.
 * @return true, if the in-memory data structures appear sound.
 */
public boolean connect(String filename) {
    // sanity check
    if (filename == null) {
        return false;
    }
    mFilename = filename;
    mLFN = new LinkedHashMap<String, ReplicaLocation>();
    mLFNRegex = new LinkedHashMap<String, ReplicaLocation>();
    mLFNPattern = new LinkedHashMap<String, Pattern>();

    File replicaFile = new File(filename);
    // first attempt to validate only if it exists
    if (replicaFile.exists() && validate(replicaFile, SCHEMA_FILE)) {
        Reader reader = null;
        try {
            reader = new VariableExpansionReader(new FileReader(filename));
            ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
            mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false);
            // inject instance of this class to be used for deserialization
            mapper.setInjectableValues(injectCallback());
            mapper.readValue(reader, YAML.class);
        } catch (IOException ioe) {
            mLFN = null;
            mLFNRegex = null;
            mLFNPattern = null;
            mFilename = null;
            throw new CatalogException(ioe); // re-throw
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException ex) {
                }
            }
        }
    }
    return true;
}
 
Example #21
Source File: Snmpman.java    From snmpman with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an {@code Snmpman} instance by the specified configuration in the {@code configurationFile} and starts all agents.
 *
 * @param configurationFile the configuration
 * @return the {@code Snmpman} instance
 * @throws com.oneandone.snmpman.exception.InitializationException thrown if any agent, as specified in the configuration, could not be started
 */
public static Snmpman start(final File configurationFile) {
    Preconditions.checkNotNull(configurationFile, "the configuration file may not be null");
    Preconditions.checkArgument(configurationFile.exists() && configurationFile.isFile(), "configuration does not exist or is not a file");

    log.debug("started with configuration in path {}", configurationFile.getAbsolutePath());
    try {
        final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        final AgentConfiguration[] configurations = mapper.readValue(configurationFile, AgentConfiguration[].class);

        return Snmpman.start(Arrays.stream(configurations).map(SnmpmanAgent::new).collect(Collectors.toList()));
    } catch (final IOException e) {
        throw new InitializationException("could not parse configuration at path: " + configurationFile.getAbsolutePath(), e);
    }
}
 
Example #22
Source File: BuildCmd.java    From product-microgateway with Apache License 2.0 5 votes vote down vote up
private String convertYamlToJson(String yaml) throws IOException {
    ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
    Object obj = yamlReader.readValue(yaml, Object.class);

    ObjectMapper jsonWriter = new ObjectMapper();
    return jsonWriter.writeValueAsString(obj);
}
 
Example #23
Source File: Meta.java    From pegasus with Apache License 2.0 5 votes vote down vote up
/**
 * Reads the on-disk map file into memory.
 *
 * @param filename is the name of the file to read.
 * @return true, if the in-memory data structures appear sound.
 */
public boolean connect(String filename) {
    // sanity check
    if (filename == null) {
        return false;
    }
    mFilename = filename;
    mLFN = new LinkedHashMap<String, ReplicaLocation>();

    File replicaFile = new File(filename);
    // first attempt to validate only if it exists
    if (replicaFile.exists()) {
        Reader reader = null;
        try {
            reader = new VariableExpansionReader(new FileReader(filename));
            ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
            mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false);
            // inject instance of this class to be used for deserialization
            mapper.setInjectableValues(injectCallback());
            mapper.readValue(reader, Meta.class);
        } catch (IOException ioe) {
            mLFN = null;
            mFilename = null;
            throw new CatalogException(ioe); // re-throw
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException ex) {
                }
            }
        }
    } else {
        return false;
    }

    return true;
}
 
Example #24
Source File: ConfigurationTest.java    From ache with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotChangeAfterSerialized() throws IOException {
    // given
    Map<?, ?> settings = ImmutableMap.of("target_storage.data_format.type", "ELASTICSEARCH");
    Configuration baseConfig = new Configuration(settings);
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

    // when
    Configuration newConfig = baseConfig.copy();
    // then
    assertEquals(baseConfig.getTargetStorageConfig().getDataFormats(),
                 newConfig.getTargetStorageConfig().getDataFormats());
    assertEquals(mapper.writeValueAsString(baseConfig), mapper.writeValueAsString(newConfig));
}
 
Example #25
Source File: DirectoryTest.java    From pegasus with Apache License 2.0 5 votes vote down vote up
@Test
public void testDirectoryDeserialization() throws IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false);

    String test =
            "  type: sharedScratch\n"
                    + "  path: /mount/workflows/scratch\n"
                    + "  freeSize: 1GB\n"
                    + "  totalSize: 122GB\n"
                    + "  fileServers:\n"
                    + "    - operation: all\n"
                    + "      url: file:///tmp/workflows/scratch\n";

    Directory dir = mapper.readValue(test, Directory.class);
    assertNotNull(dir);
    assertEquals(Directory.TYPE.shared_scratch, dir.getType());
    assertEquals(
            new InternalMountPoint("/mount/workflows/scratch", "122GB", "1GB").toString(),
            dir.getInternalMountPoint().toString());

    List<FileServer> expectedFS = new LinkedList();
    FileServer fs = new FileServer();
    PegasusURL url = new PegasusURL("file:///tmp/workflows/scratch");
    fs.setURLPrefix(url.getURLPrefix());
    fs.setProtocol(url.getProtocol());
    fs.setMountPoint(url.getPath());
    expectedFS.add(fs);

    List<FileServer> actualFS = dir.getFileServers(FileServerType.OPERATION.all);
    assertThat(actualFS, is(expectedFS));
}
 
Example #26
Source File: PasswordsUnmarshaller.java    From Patterdale with Apache License 2.0 5 votes vote down vote up
/**
 * Unmarshalls the provided 'passwords.yml' file into an in-memory representation.
 *
 * @param passwordFile the 'passwords.yml' file to be unmarshalled.
 * @return an in memory representation of the config.
 */
public Passwords parsePasswords(File passwordFile) {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    try {
        return mapper.readValue(passwordFile, Passwords.class);
    } catch (IOException e) {
        logger.error("Failed to parse provided system property 'passwords.file'.", e);
        throw new IllegalArgumentException(format("Error occurred reading passwords file '%s'", passwordFile.getName()), e);
    }
}
 
Example #27
Source File: DevfileManager.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Inject
public DevfileManager(
    DevfileSchemaValidator schemaValidator, DevfileIntegrityValidator integrityValidator) {
  this(
      schemaValidator,
      integrityValidator,
      new ObjectMapper(new YAMLFactory()),
      new ObjectMapper());
}
 
Example #28
Source File: KnowledgeBaseProfileDeserializationTest.java    From inception with Apache License 2.0 5 votes vote down vote up
@Test
public void checkThatDeserializationWorks() throws IOException
{
    String name = "Test KB";
    List<String> rootConcepts = new ArrayList<>();
    RepositoryType type = RepositoryType.LOCAL;
    Reification reification = Reification.WIKIDATA;
    String defaultLanguage = "en";

    KnowledgeBaseProfile referenceProfile = new KnowledgeBaseProfile();

    referenceProfile.setName(name);
    referenceProfile.setType(type);
    referenceProfile.setRootConcepts(rootConcepts);
    referenceProfile.setDefaultLanguage(defaultLanguage);
    referenceProfile.setReification(reification);
    referenceProfile.setMapping(createReferenceMapping());
    referenceProfile.setAccess(createReferenceAccess());
    referenceProfile.setInfo(createReferenceInfo());

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Map<String, KnowledgeBaseProfile> profiles;
    try (Reader r = new InputStreamReader(
            resolver.getResource(KNOWLEDGEBASE_TEST_PROFILES_YAML).getInputStream())) {
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        profiles = mapper.readValue(r,
                new TypeReference<HashMap<String, KnowledgeBaseProfile>>()
                {
                });
    }
    KnowledgeBaseProfile testProfile = profiles.get("test_profile");
    Assertions.assertThat(testProfile)
            .usingRecursiveComparison()
            .isEqualTo(referenceProfile);
}
 
Example #29
Source File: KnowledgeBaseServiceImpl.java    From inception with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, KnowledgeBaseProfile> readKnowledgeBaseProfiles()
    throws IOException
{
    try (Reader r = new InputStreamReader(
            getClass().getResourceAsStream(KNOWLEDGEBASE_PROFILES_YAML), UTF_8)) {
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        return mapper.readValue(r, new TypeReference<HashMap<String, KnowledgeBaseProfile>>()
        {
        });
    }
}
 
Example #30
Source File: TransformationCatalogEntryTest.java    From pegasus with Apache License 2.0 5 votes vote down vote up
@Test
public void serializeBaseEntryWithProfilesAndHooks() throws IOException {
    ObjectMapper mapper =
            new ObjectMapper(
                    new YAMLFactory().configure(YAMLGenerator.Feature.INDENT_ARRAYS, true));
    mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, false);

    TransformationCatalogEntry entry = new TransformationCatalogEntry("example", "keg", "1.0");
    entry.addProfile(
            new Profile(Profiles.NAMESPACES.env.toString(), "JAVA_HOME", "/opt/java/1.6"));

    entry.addNotification(new Invoke(Invoke.WHEN.end, "echo Test"));

    String expected =
            "---\n"
                    + "namespace: \"example\"\n"
                    + "name: \"keg\"\n"
                    + "version: \"1.0\"\n"
                    + "hooks:\n"
                    + "  shell:\n"
                    + "   -\n"
                    + "    _on: \"end\"\n"
                    + "    cmd: \"echo Test\"\n"
                    + "profiles:\n"
                    + "  env:\n"
                    + "    JAVA_HOME: \"/opt/java/1.6\"\n"
                    + "";
    String actual = mapper.writeValueAsString(entry);
    // System.err.println(actual);
    assertEquals(expected, actual);
}