Skip to content

Commit

Permalink
Dependency refresh (#203)
Browse files Browse the repository at this point in the history
* Update maven to v3.8.6

* Update to SpringBoot v2.7.6

Also bumps other dependencies for plugins and testing frameworks.

* Revert refactoring change in Facebook bot

ERROR me.ramswaroop.jbot.core.facebook.models.Event - Error serializing object:
com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: me.ramswaroop.jbot.core.facebook.models.Event["patternFromEventType"])
  • Loading branch information
jbeemster authored Dec 30, 2022
1 parent 9d45cd0 commit 6ab0d5d
Show file tree
Hide file tree
Showing 10 changed files with 295 additions and 139 deletions.
19 changes: 18 additions & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.3/apache-maven-3.3.3-bin.zip
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
23 changes: 23 additions & 0 deletions jbot-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,30 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>

<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.33</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.web.client.RestTemplate;

Expand All @@ -38,7 +38,7 @@ public class FbBotTest {
private TestBot bot;

@Rule
public OutputCapture capture = new OutputCapture();
public OutputCaptureRule capture = new OutputCaptureRule();

@Test
public void When_PostbackInCallback_Then_InvokeOnReceivePostback() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
Expand Down Expand Up @@ -47,7 +47,7 @@ public class SlackBotTest {
private TestBot bot;

@Rule
public OutputCapture capture = new OutputCapture();
public OutputCaptureRule capture = new OutputCaptureRule();

@Before
public void init() {
Expand All @@ -58,7 +58,6 @@ public void init() {
// set rtm
when(slackService.getImChannelIds()).thenReturn(Arrays.asList("D1E79BACV", "C0NDSV5B8"));
when(slackService.getCurrentUser()).thenReturn(user);
when(slackService.getWebSocketUrl()).thenReturn("");
}

@Test
Expand Down
23 changes: 23 additions & 0 deletions jbot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,30 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>

<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.33</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

Expand Down
22 changes: 19 additions & 3 deletions jbot/src/main/java/me/ramswaroop/jbot/core/facebook/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private void invokeMethods(Event event) {

methodWrappers = new ArrayList<>(methodWrappers);
MethodWrapper matchedMethod =
getMethodWithMatchingPatternAndFilterUnmatchedMethods(event.getPatternFromEventType(), methodWrappers);
getMethodWithMatchingPatternAndFilterUnmatchedMethods(getPatternFromEventType(event), methodWrappers);
if (matchedMethod != null) {
methodWrappers = new ArrayList<>();
methodWrappers.add(matchedMethod);
Expand Down Expand Up @@ -309,6 +309,22 @@ private void invokeChainedMethod(Event event) {
}
}

/**
* Match the pattern with different attributes based on the event type.
*
* @param event received from facebook
* @return the pattern string
*/
private String getPatternFromEventType(Event event) {
switch (event.getType()) {
case MESSAGE:
return event.getMessage().getText();
case QUICK_REPLY:
return event.getMessage().getQuickReply().getPayload();
case POSTBACK:
return event.getPostback().getPayload();
default:
return event.getMessage().getText();
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -305,22 +305,4 @@ public String toString() {
return null;
}
}

/**
* Match the pattern with different attributes based on the event type.
*
* @return the pattern string
*/
public String getPatternFromEventType() {
switch (getType()) {
case MESSAGE:
return getMessage().getText();
case QUICK_REPLY:
return getMessage().getQuickReply().getPayload();
case POSTBACK:
return getPostback().getPayload();
default:
return getMessage().getText();
}
}
}
Loading

0 comments on commit 6ab0d5d

Please sign in to comment.