DlmsConnectionFactory { public DlmsConnectionManager getConnection(final DlmsDevice device, final DlmsMessageListener dlmsMessageListener) throws OsgpException { return this.newConnectionWithSecurityLevel(device, dlmsMessageListener, SecurityLevel.forDevice(device)); } @Autowired  DlmsConnectionFactory(final Hls5Connector hls5Connector, final Lls1Connector lls1Connector,
            final Lls0Connector lls0Connector, final DomainHelperService domainHelperService); DlmsConnectionManager getConnection(final DlmsDevice device, final DlmsMessageListener dlmsMessageListener); DlmsConnectionManager getPublicClientConnection(final DlmsDevice device,
            final DlmsMessageListener dlmsMessageListener);  }
@Test public void returnsConnectionManagerForHls5Device() throws Exception { final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).build(); final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener(); when(this.hls5Connector.connect(device, listener)).thenReturn(this.connection); final DlmsConnectionManager result = this.factory.getConnection(device, listener); final DlmsConnectionManager expected = this.newConnectionManager(device, listener, this.hls5Connector); assertThat(result).isEqualToComparingFieldByField(expected); assertThat(result.getConnection()).isSameAs(this.connection); }
@Test public void getConnection_throwsForHls4Device() throws Exception { final DlmsDevice device = new DlmsDeviceBuilder().withHls4Active(true).build(); final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener(); assertThatExceptionOfType(FunctionalException.class).isThrownBy(() -> { this.factory.getConnection(device, listener); }); }
@Test public void getConnection_throwsForHls3Device() throws Exception { final DlmsDevice device = new DlmsDeviceBuilder().withHls3Active(true).build(); final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener(); assertThatExceptionOfType(FunctionalException.class).isThrownBy(() -> { this.factory.getConnection(device, listener); }); }
@Test public void returnsConnectionManagerForLls1Device() throws Exception { final DlmsDevice device = new DlmsDeviceBuilder().withLls1Active(true).build(); final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener(); when(this.lls1Connector.connect(device, listener)).thenReturn(this.connection); final DlmsConnectionManager result = this.factory.getConnection(device, listener); final DlmsConnectionManager expected = this.newConnectionManager(device, listener, this.lls1Connector); assertThat(result).isEqualToComparingFieldByField(expected); assertThat(result.getConnection()).isSameAs(this.connection); }
@Test public void returnsConnectionManagerForLls0Device() throws Exception { final DlmsDevice device = new DlmsDeviceBuilder().withLls1Active(false).build(); final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener(); when(this.lls0Connector.connect(device, listener)).thenReturn(this.connection); final DlmsConnectionManager result = this.factory.getConnection(device, listener); final DlmsConnectionManager expected = this.newConnectionManager(device, listener, this.lls0Connector); assertThat(result).isEqualToComparingFieldByField(expected); assertThat(result.getConnection()).isSameAs(this.connection); }