@Test public void testRetrieveSampleWithEmptyDescription() throws SampleRetrievalException { Assert.assertNull(reader.readSample(SERVICE_NAME, "EmptyDescriptionSample")); }
public RetrievedCodeSample readSample(final String serviceName, final String sampleId) throws SampleRetrievalException { ValidationUtils.assertInputNotEmpty(serviceName, "Sample service name must be provided"); ValidationUtils.assertInputNotEmpty(sampleId, "Sample ID must be provided"); String targetSampleFile = String.format("/%s/%s.xml", sampleDir, serviceName); InputStream in = getClass().getResourceAsStream(targetSampleFile); if (in == null) { return null; } SampleCodeXMLParser parser = new SampleCodeXMLParser(sampleId); try { saxParser.parse(in, parser); } catch (Exception e) { throw new SampleRetrievalException("Could not parse sample", serviceName, sampleId, e); } String sampleContent = parser.getSampleContent(); String sampleTitle = parser.getSampleTitle(); String sampleDescription = parser.getSampleDescription(); if (ValidationUtils.areNullOrEmpty(sampleContent, sampleTitle, sampleDescription)) { return null; } return new RetrievedCodeSample(sampleId, serviceName, sampleTitle, sampleDescription, sampleContent); }
SampleCodeReader { public RetrievedCodeSample readSample(final String serviceName, final String sampleId) throws SampleRetrievalException { ValidationUtils.assertInputNotEmpty(serviceName, "Sample service name must be provided"); ValidationUtils.assertInputNotEmpty(sampleId, "Sample ID must be provided"); String targetSampleFile = String.format("/%s/%s.xml", sampleDir, serviceName); InputStream in = getClass().getResourceAsStream(targetSampleFile); if (in == null) { return null; } SampleCodeXMLParser parser = new SampleCodeXMLParser(sampleId); try { saxParser.parse(in, parser); } catch (Exception e) { throw new SampleRetrievalException("Could not parse sample", serviceName, sampleId, e); } String sampleContent = parser.getSampleContent(); String sampleTitle = parser.getSampleTitle(); String sampleDescription = parser.getSampleDescription(); if (ValidationUtils.areNullOrEmpty(sampleContent, sampleTitle, sampleDescription)) { return null; } return new RetrievedCodeSample(sampleId, serviceName, sampleTitle, sampleDescription, sampleContent); } }
SampleCodeReader { public RetrievedCodeSample readSample(final String serviceName, final String sampleId) throws SampleRetrievalException { ValidationUtils.assertInputNotEmpty(serviceName, "Sample service name must be provided"); ValidationUtils.assertInputNotEmpty(sampleId, "Sample ID must be provided"); String targetSampleFile = String.format("/%s/%s.xml", sampleDir, serviceName); InputStream in = getClass().getResourceAsStream(targetSampleFile); if (in == null) { return null; } SampleCodeXMLParser parser = new SampleCodeXMLParser(sampleId); try { saxParser.parse(in, parser); } catch (Exception e) { throw new SampleRetrievalException("Could not parse sample", serviceName, sampleId, e); } String sampleContent = parser.getSampleContent(); String sampleTitle = parser.getSampleTitle(); String sampleDescription = parser.getSampleDescription(); if (ValidationUtils.areNullOrEmpty(sampleContent, sampleTitle, sampleDescription)) { return null; } return new RetrievedCodeSample(sampleId, serviceName, sampleTitle, sampleDescription, sampleContent); } SampleCodeReader(final String sampleDir); }
SampleCodeReader { public RetrievedCodeSample readSample(final String serviceName, final String sampleId) throws SampleRetrievalException { ValidationUtils.assertInputNotEmpty(serviceName, "Sample service name must be provided"); ValidationUtils.assertInputNotEmpty(sampleId, "Sample ID must be provided"); String targetSampleFile = String.format("/%s/%s.xml", sampleDir, serviceName); InputStream in = getClass().getResourceAsStream(targetSampleFile); if (in == null) { return null; } SampleCodeXMLParser parser = new SampleCodeXMLParser(sampleId); try { saxParser.parse(in, parser); } catch (Exception e) { throw new SampleRetrievalException("Could not parse sample", serviceName, sampleId, e); } String sampleContent = parser.getSampleContent(); String sampleTitle = parser.getSampleTitle(); String sampleDescription = parser.getSampleDescription(); if (ValidationUtils.areNullOrEmpty(sampleContent, sampleTitle, sampleDescription)) { return null; } return new RetrievedCodeSample(sampleId, serviceName, sampleTitle, sampleDescription, sampleContent); } SampleCodeReader(final String sampleDir); RetrievedCodeSample readSample(final String serviceName,
            final String sampleId); }
SampleCodeReader { public RetrievedCodeSample readSample(final String serviceName, final String sampleId) throws SampleRetrievalException { ValidationUtils.assertInputNotEmpty(serviceName, "Sample service name must be provided"); ValidationUtils.assertInputNotEmpty(sampleId, "Sample ID must be provided"); String targetSampleFile = String.format("/%s/%s.xml", sampleDir, serviceName); InputStream in = getClass().getResourceAsStream(targetSampleFile); if (in == null) { return null; } SampleCodeXMLParser parser = new SampleCodeXMLParser(sampleId); try { saxParser.parse(in, parser); } catch (Exception e) { throw new SampleRetrievalException("Could not parse sample", serviceName, sampleId, e); } String sampleContent = parser.getSampleContent(); String sampleTitle = parser.getSampleTitle(); String sampleDescription = parser.getSampleDescription(); if (ValidationUtils.areNullOrEmpty(sampleContent, sampleTitle, sampleDescription)) { return null; } return new RetrievedCodeSample(sampleId, serviceName, sampleTitle, sampleDescription, sampleContent); } SampleCodeReader(final String sampleDir); RetrievedCodeSample readSample(final String serviceName,
            final String sampleId);  }