AltoNorthboundRouteEndpointproperty implements AltoNorthboundRoute { protected Response buildOutput(QueryInput input, QueryOutput output) throws JsonProcessingException { EndpointpropertyResponse epResponse = (EndpointpropertyResponse) output.getResponse(); EndpointPropertymapData epMapData = (EndpointPropertymapData) epResponse.getEndpointpropertyData(); EndpointPropertyMap epMap = epMapData.getEndpointPropertyMap(); List<EndpointProperty> linkEndpointProperty = epMap.getEndpointProperty(); Map<String, Map<String, String>> endpointpropertyMap = new HashMap<>(); for (EndpointProperty ep: linkEndpointProperty) { Map<String, String> propertyMap = new HashMap<>(); Source source = ep.getSource(); String endpointSourceAddress = getAddressValue(source.getAddress()); List<Properties> properties = ep.getProperties(); for (Properties property: properties) { PropertyValue propertyValue = property.getPropertyValue(); if (property.getPropertyContainer().getProperty() instanceof OutputResourceSpecificProperty) propertyMap.put(((OutputResourceSpecificProperty)property.getPropertyContainer().getProperty()).getResourceSpecificProperty().getValue(), ((PidName)propertyValue).getValue().getValue()); else { propertyMap.put(((OutputGlobalProperty)property.getPropertyContainer().getProperty()).getGlobalProperty().getValue(), ((PidName)propertyValue).getValue().getValue()); } } endpointpropertyMap.put(endpointSourceAddress, propertyMap); } RFC7285EndpointPropertyMap rfcEPM= new RFC7285EndpointPropertyMap(); rfcEPM.map = endpointpropertyMap; rfcEPM.meta = buildMeta(input.getServiceReference()); String responseString = mapper.writeValueAsString(rfcEPM); return Response.ok(responseString, ALTO_ENDPOINTPROPERTY).build(); }  void setDataBroker(DataBroker dataBroker); void setMapService(final AltoModelEndpointpropertyService mapService); void init(); void register(AltoNorthboundRouter router); void close(); @Path("{path}") @POST @Consumes({ALTO_ENDPOINTPROPERTY_FILTER}) @Produces({ALTO_ENDPOINTPROPERTY, ALTO_ERROR}) Response getEndpointProperty(@PathParam("path") String path, String content); InstanceIdentifier<ContextTag> getResourceByPath(String path, ReadOnlyTransaction transaction); static final String ALTO_ENDPOINTPROPERTY_FILTER; static final String ALTO_ENDPOINTPROPERTY; static final String FIELD_PROPERTIES; static final String FIELD_ENDPOINTS; static final String IPv4_PREFIX; static final String IPv6_PREFIX; static final String PRIV_PREFIX; }
@Test public void testBuildOutput() throws IOException, ExecutionException, InterruptedException{ AltoNorthboundRouteEndpointproperty anbreSpy = spy(anbre); InstanceIdentifier<ContextTag> ctagIID = InstanceIdentifier.create(ContextTag.class); AltoModelEndpointpropertyService epService = mock(AltoModelEndpointpropertyService.class); Future<RpcResult<QueryOutput>> future = mock(Future.class); RpcResult<QueryOutput> rpcResult =mock(RpcResult.class); LinkedList<EndpointProperty> eppist = new LinkedList<>(); SourceBuilder sourceBuilder = new SourceBuilder(); Source THE_FIRST_SOURCE = sourceBuilder.setAddress( new Ipv4Builder() .setIpv4(new Ipv4Address(THE_FIRST_IPv4_ADDRESS)) .build()) .build(); Source THE_SECOND_SOURCE = sourceBuilder.setAddress( new Ipv4Builder() .setIpv4(new Ipv4Address(THE_SECOND_IPv4_ADDRESS)) .build()) .build(); EndpointPropertyBuilder epBuilder = new EndpointPropertyBuilder(); List<Properties> THE_FIRST_LIST_PROPERTIES = new LinkedList<>(); List<Properties> THE_SECOND_LIST_PROPERTIES = new LinkedList<>(); PropertiesBuilder propertiesBuilder = new PropertiesBuilder(); PropertyContainerBuilder pcBuilder = new PropertyContainerBuilder(); PidName pidName = new PidName("PID1"); PidNameBuilder pidNameBuilder = new PidNameBuilder(); pidNameBuilder.setValue(pidName); pcBuilder.setProperty( new OutputResourceSpecificPropertyBuilder() .setResourceSpecificProperty(new SpecificEndpointProperty(DEFAULT_NETWORKMAP)).build()); propertiesBuilder.setPropertyContainer(pcBuilder.build()).setPropertyValue(pidNameBuilder.build()); THE_FIRST_LIST_PROPERTIES.add(propertiesBuilder.build()); pcBuilder.setProperty( new OutputGlobalPropertyBuilder() .setGlobalProperty(new GlobalEndpointProperty(DEFAULT_GLOBAL_PROPERTY_NAME)) .build() ); PidName fackGlobalProperty = new PidName("1"); pidNameBuilder.setValue(fackGlobalProperty); propertiesBuilder.setPropertyContainer(pcBuilder.build()).setPropertyValue(pidNameBuilder.build()); THE_FIRST_LIST_PROPERTIES.add(propertiesBuilder.build()); pidName = new PidName("PID3"); pidNameBuilder.setValue(pidName); pcBuilder.setProperty( new OutputResourceSpecificPropertyBuilder(). setResourceSpecificProperty(new SpecificEndpointProperty(DEFAULT_NETWORKMAP)).build()); propertiesBuilder.setPropertyContainer(pcBuilder.build()).setPropertyValue(pidNameBuilder.build()); THE_SECOND_LIST_PROPERTIES.add(propertiesBuilder.build()); eppist.add( epBuilder .setSource(THE_FIRST_SOURCE) .setProperties(THE_FIRST_LIST_PROPERTIES) .build()); eppist.add( epBuilder .setSource(THE_SECOND_SOURCE) .setProperties(THE_SECOND_LIST_PROPERTIES).build()); EndpointPropertyMapBuilder endpointPropertyMapBuilder = new EndpointPropertyMapBuilder(); endpointPropertyMapBuilder.setEndpointProperty(eppist); EndpointPropertymapDataBuilder endpointPropertymapDataBuilder = new EndpointPropertymapDataBuilder(); endpointPropertymapDataBuilder.setEndpointPropertyMap(endpointPropertyMapBuilder.build()); EndpointpropertyResponseBuilder endpointpropertyResponseBuilder = new EndpointpropertyResponseBuilder(); endpointpropertyResponseBuilder.setEndpointpropertyData(endpointPropertymapDataBuilder.build()); QueryOutputBuilder queryOutputBuilder = new QueryOutputBuilder(); queryOutputBuilder.setType(ResourceTypeEndpointproperty.class).setResponse(endpointpropertyResponseBuilder.build()); when(rpcResult.getResult()).thenReturn(queryOutputBuilder.build()); when(future.get()).thenReturn(rpcResult); when(epService.query((QueryInput) anyObject())).thenReturn(future); anbreSpy.setMapService(epService); anbreSpy.setDataBroker(mock(DataBroker.class)); doReturn(ctagIID).when(anbreSpy).getResourceByPath(eq(PATH), (ReadOnlyTransaction) anyObject()); RFC7285EndpointPropertyMap.Meta meta = new RFC7285EndpointPropertyMap.Meta(); RFC7285VersionTag vtag = new RFC7285VersionTag(); vtag.rid = DEFAULT_RID; vtag.tag = DEFAULT_TAG; meta.netmap_tags = new LinkedList<>(); meta.netmap_tags.add(vtag); doReturn(meta).when(anbreSpy).buildMeta((InstanceIdentifier<?>) anyObject()); anbreSpy.init(); Response response = anbreSpy.getEndpointProperty(PATH, ENDPOINTPROPERTY_FILTER); String stringResponse = response.getEntity().toString(); ObjectMapper mapper = new ObjectMapper(); JsonNode responseNode = mapper.readTree(stringResponse); JsonNode endpointProperties = responseNode.get(FIELD_ENDPOINT_PROPERTIES); JsonNode expectedEndpointProperties = mapper.readTree(TARGET_ENDPOINT_PREOPERTIES); assertEquals(expectedEndpointProperties, endpointProperties); }