abruzzi / consulting

2 stars 0 forks source link

Java 8 Stream API #6

Closed abruzzi closed 8 years ago

abruzzi commented 8 years ago
    @Test
    public void should_fulfill_subscription_based_on_single_event_and_config() throws IOException {
        List<NEBusinessSubInfo> neBusinessSubInfoList = prepareNeBusinessSubInfo();

        EventDefinition eventDefinition = prepareEventDefinition("/e-rab-setup-request-1.xml");
        BusinessService businessService = new BusinessService(eventDefinition);

        Subscription subscription = businessService.process(neBusinessSubInfoList);

        assertThat(subscription.getCounters(), hasSize(1));

        Counter expected = new Counter("NE256", "LTE_CELL_TRC", "30101");
        Counter counter = subscription.getCounters().get(0);

        assertThat(counter, is(expected));
    }
abruzzi commented 8 years ago
<?xml version="1.0" encoding="UTF-8"?>
<EventDefs>
  <NBIMappingNode>
    <EventList>
      <event id="0x0100" level="1"> 
        <businessSrbPara> 
          <para name="srbID" value="30101" />
          <para name="datasource" value="LTE_CELL_TRC " />
        </businessSrbPara>
      </event>
    </EventList>
  </NBIMappingNode>
</EventDefs>
abruzzi commented 8 years ago
    @Test
    public void should_generate_multiple_counters_given_multiple_datasource_and_config() throws IOException {
        List<NEBusinessSubInfo> neBusinessSubInfoList = prepareNeBusinessSubInfo();

        EventDefinition eventDefinition = prepareEventDefinition("/e-rab-setup-request-2-1.xml");
        BusinessService businessService = new BusinessService(eventDefinition);

        Subscription subscription = businessService.process(neBusinessSubInfoList);

        assertThat(subscription.getCounters(), hasSize(2));

        Counter expected1 = new Counter("NE256", "LTE_CELL_TRC", "30101");
        Counter c1 = subscription.getCounters().get(0);
        assertThat(c1, is(expected1));

        Counter expected2 = new Counter("NE256", "PICO_CELL_TRC", "30101");
        Counter c2 = subscription.getCounters().get(1);
        assertThat(c2, is(expected2));
    }
abruzzi commented 8 years ago
    private EventDefinition prepareEventDefinition(String fileName) throws java.io.IOException {
        JacksonXmlModule module = new JacksonXmlModule();
        module.setDefaultUseWrapper(false);
        XmlMapper xmlMapper = new XmlMapper(module);

        return xmlMapper.readValue(getClass().getResourceAsStream(fileName), EventDefinition.class);
    }

    private List<NEBusinessSubInfo> prepareNeBusinessSubInfo() {
        NEBusinessSubInfo neBusinessSubInfo = new NEBusinessSubInfo("NE=256", "0", new String[]{"0x0100"});
        List<NEBusinessSubInfo> neBusinessSubInfoList = new ArrayList<>();
        neBusinessSubInfoList.add(neBusinessSubInfo);
        return neBusinessSubInfoList;
    }