initial check-in for project to implement a minimal ActivityPub bot in Java/Spring
This commit is contained in:
parent
54508a2890
commit
516652c11c
14 changed files with 560 additions and 0 deletions
|
|
@ -0,0 +1,34 @@
|
|||
package dev.activitypub.activitypubbot;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
//import org.springframework.boot.SpringApplication;
|
||||
//import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ActivityPubBotApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ActivityPubBotApplication.class, args);
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
|
||||
return args -> {
|
||||
System.out.println("Beany McBeanface");
|
||||
|
||||
String[] beanNames = ctx.getBeanDefinitionNames();
|
||||
Arrays.sort(beanNames);
|
||||
for (String beanName : beanNames) {
|
||||
System.out.println(beanName);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package dev.activitypub.activitypubbot;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class HomeController {
|
||||
|
||||
@GetMapping("/")
|
||||
public String index() {
|
||||
return "Parsnip!";
|
||||
}
|
||||
|
||||
@GetMapping("/actor")
|
||||
public String actor() {
|
||||
return """
|
||||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1"
|
||||
],
|
||||
|
||||
"id": "https://springap.seth.id.au/actor",
|
||||
"type": "Bot",
|
||||
"preferredUsername": "SpringBot
|
||||
"inbox": "https://springap.seth.id.au/inbox",
|
||||
|
||||
"publicKey": {
|
||||
"id": "https://springap.seth.id.au/actor#main-key",
|
||||
"owner": "https://springap.seth.id.au/actor",
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----"
|
||||
}
|
||||
}""";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
spring.application.name=activitypubbot
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package dev.activitypub.activitypubbot;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class ActivityPubBotApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package dev.activitypub.activitypubbot;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
public class HomeControllerTest {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
public void getHome() throws Exception {
|
||||
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(equalTo("Parsnip!")));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue