/** * A local OBIX server has to be running in order to pass this test. * * <p>The IoTSYS System can be used for this: https://github.com/mjung85/iotsys/ */ @Test public void getLobbyShouldReturnEmptyLobbyOnlyWithResponseString() { String uri = "localhost/obix"; CoapClient coapClient = new CoapClient(uri); // False, if the coap client is offline org.junit.Assume.assumeTrue(coapClient.ping()); ObixLobby lobby = undecoratedCoapChannel.getLobby(uri); Assert.assertThat(lobby.getLobbyAsString(), CoreMatchers.containsString("href=\"obix/\"")); }
/** * This method represents the window in which the preferred obix components can be chosen. * * @return The container in which the preferred obix components can be chosen. */ private Container chooseComponents() { Container pane = new Container(); pane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = 1; c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 1; c.insets = new Insets(5, 5, 5, 5); registeredColibriChannelCheckBox = new JCheckBox("IS REGISTERD ON COLIBRI SEMANTIC CORE"); commandFactory.addCommand( () -> registeredColibriChannelCheckBox.setSelected( connector.getColibriChannel().getRegistered())); Font regF = new Font("Courier", Font.BOLD, 40); registeredColibriChannelCheckBox.setFont(regF); /** * Listener for the checkbox which indicates, if the obix connector is registered at colibri. */ registeredColibriChannelCheckBox.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { if (!connector.getColibriChannel().getRegistered()) { connector.getColibriChannel().send(ColibriMessage.createRegisterMessage(connector)); } } else { if (connector.getColibriChannel().getRegistered()) { connector .getColibriChannel() .send(ColibriMessage.createDeregisterMessage(connector)); } } } }); pane.add(registeredColibriChannelCheckBox, c); Font titelF = new Font("Courier", Font.BOLD, 30); title = new JLabel("Please choose the components you want to work with"); title.setFont(titelF); c.gridy++; pane.add(title, c); JTextField searchTextField = new JTextField("Search for a component"); c.weightx = 1; c.weighty = 1; c.gridx++; pane.add(searchTextField, c); c.weightx = 0.25; c.weighty = 0.25; c.gridwidth = 1; c.gridx++; JButton searchButton = new JButton("Search"); pane.add(searchButton, c); JCheckBox markAllCheckbox = new JCheckBox("Mark all components"); c.gridy++; c.gridy++; pane.add(markAllCheckbox, c); for (String s : lobby.getObservedObjectsLists().keySet()) { if (!s.equals("all")) { List<ObixObject> objects = lobby.getObservedObjectsLists().get(s); JLabel header = new JLabel(s); Font headerF = new Font("Courier", Font.BOLD, 25); header.setFont(headerF); c.gridx = 0; c.gridy++; pane.add(header, c); for (ObixObject o : objects) { JCheckBox chooseCheckBox = new JCheckBox(o.getObixUri()); JPanel innerPanel = new JPanel(); innerPanel.setLayout(new FlowLayout(0, 0, 0)); innerPanel.add(chooseCheckBox); c.gridx = 0; c.gridwidth = 10; c.gridy++; pane.add(innerPanel, c); representationRows.add(new RepresentationRow(o, chooseCheckBox)); } } } JButton acceptButton = new JButton("Accept"); c.gridx = 0; c.gridy++; pane.add(acceptButton, c); /** Accept button listener */ Action acceptAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { List<ObixObject> chosenObjects = Collections.synchronizedList(new ArrayList<>()); ; for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) { if (r.getChooseCheckbox().isSelected()) { chosenObjects.add(r.getObixObject()); } } representationRows.clear(); cards.removeAll(); JScrollPane scrollPane = new JScrollPane(chooseParameters(chosenObjects)); scrollPane.getVerticalScrollBar().setUnitIncrement(16); scrollPane.setBorder(new EmptyBorder(20, 20, 20, 20)); cards.add(scrollPane); // Display the window. mainFrame.pack(); } }; acceptButton.addActionListener(acceptAction); /** Search function listener */ Action searchAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { String searchText = searchTextField.getText(); for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) { if (r.getChooseCheckbox().getText().contains(searchText)) { r.getChooseCheckbox().setForeground(Color.blue); } else { r.getChooseCheckbox().setForeground(Color.black); } r.getChooseCheckbox().revalidate(); r.getChooseCheckbox().repaint(); } } }; searchTextField.addActionListener(searchAction); searchButton.addActionListener(searchAction); /** Mark all components function listener */ Action markAllAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) { r.getChooseCheckbox().setSelected(true); } } }; markAllCheckbox.addActionListener(markAllAction); return pane; }
@Test() public void getLobbyWithWrongURIShouldReturnErr() { ObixLobby lobby = undecoratedCoapChannel.getLobby("wrong"); Obj lobbyObj = ObixXmlChannelDecorator.decode(lobby.getLobbyAsString()); Assert.assertTrue(lobbyObj.isErr()); }