Package hudson.plugins.im

Examples of hudson.plugins.im.Sender


    public void onMessage(IMMessage msg) {
        // is it a command for me ? (returns null if not, the payload if so)
        String payload = retrieveMessagePayLoad(msg.getBody());
        if (payload != null) {
            Sender s = getSender(msg);
         
          try {
              if (!this.commandsAccepted) {
                  this.chat.sendMessage(s.getNickname() + " you may not issue bot commands in this chat!");
                  return;
              } else if (!msg.isAuthorized()) {
            this.chat.sendMessage(s.getNickname() + " you're not a buddy of me. I won't take any commands from you!");
            return;
              }
          } catch (IMException e) {
                LOGGER.warning(ExceptionHelper.dump(e));
                return;
            }
         
            // split words
            String[] args = MessageHelper.extractCommandLine(payload);
            if (args.length > 0) {
                // first word is the command name
                String cmd = args[0];
               
                try {
                  BotCommand command = this.cmdsAndAliases.get(cmd);
                    if (command != null) {
                      Authentication oldAuthentication = SecurityContextHolder.getContext().getAuthentication();
                      try {
                          if (this.authentication != null) {
                              SecurityContextHolder.getContext().setAuthentication(this.authentication.getAuthentication());
                          }
                        command.executeCommand(this, this.chat, msg, s, args);
                      } finally {
                          if (this.authentication != null) {
                              SecurityContextHolder.getContext().setAuthentication(oldAuthentication);
                          }
                      }
                    } else {
                        this.chat.sendMessage(s.getNickname() + " did you mean me? Unknown command '" + cmd
                                + "'\nUse '" + this.commandPrefix + " help' to get help!");
                    }
                } catch (IMException e) {
                    LOGGER.warning(ExceptionHelper.dump(e));
                }
View Full Code Here


  private Sender getSender(IMMessage msg) {
      String sender = msg.getFrom();
      String id = this.chat.getIMId(sender);
       
        final Sender s;
        if (id != null) {
            s = new Sender(this.chat.getNickName(sender), id);
        } else {
            s = new Sender(this.chat.getNickName(sender));
        }
        return s;
    }
View Full Code Here

        AbstractProject project = mock(AbstractProject.class);
        AbstractBuild<?, ?> build = mock(AbstractBuild.class);
        when(project.getBuildByNumber(4711)).thenReturn(build);
       
        CommentCommand command = new CommentCommand();
        String result = command.getMessageForJob(project, new Sender("kutzi"),
                new String[] { "4711", "my comment"}).toString();
        assertEquals("Ok", result);
       
        verify(build).setDescription("my comment");
    }
View Full Code Here

    @Test(expected = CommandException.class)
    public void testMalformedBuildNumber() throws CommandException {
        AbstractProject<?, ?> project = mock(AbstractProject.class);
       
        CommentCommand command = new CommentCommand();
        command.getMessageForJob(project, new Sender("kutzi"),
                new String[] { "abc", "my comment"}).toString();
    }
View Full Code Here

        AbstractProject project = mock(AbstractProject.class);
        AbstractBuild<?, ?> build = mock(AbstractBuild.class);
        when(project.getBuildByNumber(4711)).thenReturn(build);
       
        CommentCommand command = new CommentCommand();
        command.getMessageForJob(project, new Sender("kutzi"),
                new String[] { "4712", "my comment"}).toString();
    }
View Full Code Here

  public void testNoJobFound() {
      JobProvider jobProvider = mock(JobProvider.class);
    HealthCommand cmd = new HealthCommand();
    cmd.setJobProvider(jobProvider);
   
    Sender sender = new Sender("tester");
    String[] args = {"health"};
    String reply = cmd.getReply(null, sender, args);
   
    assertEquals(sender + ": no job found", reply);
  }
View Full Code Here

     * Test of executeCommand method, of class SnackCommand.
     */
    @Test
    public void testExecuteCommand() throws Exception {
        SnackCommand cmd = new SnackCommand();
        Sender sender = new Sender("tester");
        String[] args = { "!botsnack", "peanuts" };

        String reply = cmd.getReply(null, sender, args);
        System.out.println(reply);
        assertNotNull(reply);
        assertTrue(reply.contains(sender.getNickname()));
        assertTrue(reply.contains("peanuts"));
       
        args = new String[] { "!botsnack" };
        reply = cmd.getReply(null, sender, args);
        System.out.println(reply);
        assertNotNull(reply);
        assertTrue(reply.contains(sender.getNickname()));
    }
View Full Code Here

       
        HealthCommand cmd = new HealthCommand();
        cmd.setJobProvider(jobProvider);
       
        List<AbstractProject<?, ?>> projects = new ArrayList<AbstractProject<?,?>>();
        Pair<Mode, String> pair = cmd.getProjects(new Sender("sender"), args, projects);
       
        assertEquals(Mode.SINGLE, pair.getHead());
        assertNull(pair.getTail());
       
        assertEquals(1, projects.size());
View Full Code Here

       
        HealthCommand cmd = new HealthCommand();
        cmd.setJobProvider(jobProvider);
       
        List<AbstractProject<?, ?>> projects = new ArrayList<AbstractProject<?,?>>();
        cmd.getProjects(new Sender("sender"), args, projects);
    }
View Full Code Here

        String[] args = { "health", "-v", viewName };
        HealthCommand cmd = new HealthCommand();
        cmd.setJobProvider(jobProvider);
       
        List<AbstractProject<?, ?>> projects = new ArrayList<AbstractProject<?,?>>();
        Pair<Mode,String> pair = cmd.getProjects(new Sender("sender"), args, projects);

        assertEquals(Mode.VIEW, pair.getHead());
        assertEquals(viewName, pair.getTail());
       
        assertEquals(1, projects.size());
View Full Code Here

TOP

Related Classes of hudson.plugins.im.Sender

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.