CatalogInputAdapter { public ResourceRequest buildReadRequest(Metacard metacard, String qualifier) { if (metacard == null) { throw new IllegalArgumentException("method argument 'metacard' may not be null."); } if (qualifier == null) { throw new IllegalArgumentException("method argument 'qualifier' may not be null."); } Attribute attribute = metacard.getAttribute(Core.RESOURCE_URI); if (attribute != null) { Serializable value = attribute.getValue(); if (value == null) { throw new IllegalStateException( String.format("metacard attribute %s has no value assigned.", Core.RESOURCE_URI)); } Map<String, Serializable> props = new HashMap<>(); props.put(ContentItem.QUALIFIER_KEYWORD, qualifier); try { return new ResourceRequestByProductUri(new URI((String) value), props); } catch (URISyntaxException e) { throw new IllegalArgumentException( String.format( "The supplied metacard does contains an invalid '%s' attribute.", Core.RESOURCE_URI)); } } throw new IllegalStateException( String.format( "The supplied metacard does not contain the '%s' attribute.", Core.RESOURCE_URI)); }  ResourceRequest buildReadRequest(Metacard metacard, String qualifier); @SuppressWarnings("unused") ResourceRequest buildReadRequest(Metacard metacard); String getResourceSiteName(Metacard metacard);  }
@Test(expected = IllegalArgumentException.class) public void testNullMetacard() throws URISyntaxException { catalogInputAdapter.buildReadRequest(null, OVERVIEW); }
@Test(expected = IllegalStateException.class) public void testNullAttribute() throws URISyntaxException { when(mockMetacard.getAttribute(anyString())).thenReturn(null); catalogInputAdapter.buildReadRequest(mockMetacard, OVERVIEW); }
@Test(expected = IllegalStateException.class) public void testNullAttributeValue() throws URISyntaxException { when(mockAttribute.getValues()).thenReturn(null); when(mockMetacard.getAttribute(anyString())).thenReturn(mockAttribute); catalogInputAdapter.buildReadRequest(mockMetacard, OVERVIEW); }
@Test(expected = IllegalArgumentException.class) public void testMalformedURI() throws URISyntaxException { Attribute attribute = mock(Attribute.class); when(attribute.getName()).thenReturn(Metacard.RESOURCE_URI); when(attribute.getValue()).thenReturn(" "); Metacard metacard = mock(Metacard.class); when(metacard.getAttribute(anyString())).thenReturn(attribute); catalogInputAdapter.buildReadRequest(metacard, OVERVIEW); }
@Test public void testSuccessfulCase() throws URISyntaxException { Attribute attribute = mock(Attribute.class); when(attribute.getName()).thenReturn(Metacard.RESOURCE_URI); when(attribute.getValue()).thenReturn("content:10101#overview"); Metacard metacard = mock(Metacard.class); when(metacard.getAttribute(anyString())).thenReturn(attribute); ResourceRequest request = catalogInputAdapter.buildReadRequest(metacard, OVERVIEW); assertThat(request.getAttributeName(), is(Metacard.RESOURCE_URI)); assertThat(request.getAttributeValue().toString(), is("content:10101#overview")); assertThat(request.getProperties().get(ContentItem.QUALIFIER_KEYWORD), is(OVERVIEW)); }
@Test public void testBuildRequest() { String id = "abcd"; MetacardImpl metacard = new MetacardImpl(); metacard.setId(id); ResourceRequest resourceRequest = catalogInputAdapter.buildReadRequest(metacard); assertThat(resourceRequest.getAttributeValue(), is(id)); }