Skip to content

Commit

Permalink
test: init intergratio test for hello controller
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Oct 10, 2022
1 parent 4420b5b commit 6c6c988
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 5 deletions.
2 changes: 2 additions & 0 deletions fkl_cli/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.java
test_data/**/build/**
!test_data/**/*.java
16 changes: 16 additions & 0 deletions fkl_cli/src/e2e.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use crate::code_gen_exec;

#[test]
fn test_java_package_to_path() {
let d: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let base_path = d.clone();

let mut input_path = d.clone();
input_path.push(format!("test_data/spring/spring.fkl"));

code_gen_exec::code_gen_exec(Some(&input_path), Some(&"HelloGot".to_string()), &base_path);
}
}
17 changes: 13 additions & 4 deletions fkl_cli/src/exec/code_gen_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum DddLayer {
Infrastructure,
}

pub fn code_gen_exec(feakin_path: Option<&PathBuf>, filter_impl: Option<&String>) {
pub fn code_gen_exec(feakin_path: Option<&PathBuf>, filter_impl: Option<&String>, base_path: &PathBuf) {
if feakin_path.is_none() {
error!("Please provide a path to a manifest file");
return;
Expand All @@ -45,12 +45,21 @@ pub fn code_gen_exec(feakin_path: Option<&PathBuf>, filter_impl: Option<&String>

code_blocks.iter().for_each(|code_block| {
let file_name = code_block.class_name.clone() + ".java";
let target_path: String = layer_map.interface_path().clone() + &file_name;
let code_file = JavaIdent::parse(&target_path);
let mut target_path = base_path.clone();
target_path.push(layer_map.interface_path().clone());
target_path.push(file_name);

if !target_path.exists() {
panic!("target file not found: {}", target_path.to_str().unwrap());
}

let path = format!("{}", target_path.display());

let code_file = JavaIdent::parse(&path);
let first_class = &code_file.classes[0];

let lines: Vec<String> = code_block.code.split("\n").map(|s| s.to_string()).collect();
JavaInserter::insert(&target_path, first_class, lines)
JavaInserter::insert(&path, first_class, lines)
.expect("TODO: panic message");
});
}
Expand Down
1 change: 1 addition & 0 deletions fkl_cli/src/inserter/inserter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl JavaInserter {

#[cfg(test)]
mod tests {
use std::fs;
use crate::class_info::CodePoint;

use super::*;
Expand Down
3 changes: 2 additions & 1 deletion fkl_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod class_info;
pub mod inserter;
pub mod exec;
pub mod line_separator;
mod e2e;

// todo: add code highlight support
fn main() {
Expand Down Expand Up @@ -54,7 +55,7 @@ fn main() {
let feakin_path = matches.get_one::<PathBuf>("path");
let filter_impl = matches.get_one::<String>("impl");

code_gen_exec::code_gen_exec(feakin_path, filter_impl);
code_gen_exec::code_gen_exec(feakin_path, filter_impl, &PathBuf::from("."));
}
Some(("dot", matches)) => {
let manifest_path = matches.get_one::<PathBuf>("path");
Expand Down
24 changes: 24 additions & 0 deletions fkl_cli/test_data/spring/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
plugins {
id 'org.springframework.boot' version '3.0.0-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.14.RELEASE'
id 'java'
}

group = 'com.feakin'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
useJUnitPlatform()
}
8 changes: 8 additions & 0 deletions fkl_cli/test_data/spring/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pluginManagement {
repositories {
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
gradlePluginPortal()
}
}
rootProject.name = 'demo'
28 changes: 28 additions & 0 deletions fkl_cli/test_data/spring/spring.fkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
impl HelloGot {
endpoint {
GET "/hello";
response: String;
}
}

layered DDD {
dependency {
"interface" -> "application"
"interface" -> "domain"
"domain" -> "application"
"application" -> "infrastructure"
"interface" -> "infrastructure"
}
layer interface {
package: "com.feakin.demo.interface";
}
layer domain {
package: "com.feakin.demo.domain";
}
layer application {
package: "com.feakin.demo.application";
}
layer infrastructure {
package: "com.feakin.demo.infrastructure";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.feakin.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.feakin.demo.interface;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

@GetMapping("/")
public String index() {
return "Greetings from Spring Boot!";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.feakin.demo;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class DemoApplicationTests {

@Test
void contextLoads() {
}

}

0 comments on commit 6c6c988

Please sign in to comment.