Skip to content

Commit

Permalink
End to end test
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitk-h committed Jun 8, 2021
1 parent a053e3d commit f4235c3
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 153 deletions.
2 changes: 2 additions & 0 deletions src/cmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ go_library(
"@com_github_mitchellh_go_homedir//:go_default_library",
"@com_github_spf13_cobra//:go_default_library",
"@com_github_spf13_viper//:go_default_library",
"//src/compiler:go_default_library",
"//src/dom/parser:go_default_library",
],
)
156 changes: 5 additions & 151 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,160 +2,17 @@ package cmd

import (
"fmt"
"github.com/query-builder-generator/src/compiler"
"os"
"github.com/spf13/cobra"
"io/ioutil"
"strings"

"github.com/query-builder-generator/src/dom/parser"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
)

var cfgFile string

var outputContentWithoutDelegateId = `
package io.harness.beans;
import io.harness.beans.DelegateTask.DelegateTaskKeys;
import io.harness.persistence.HPersistence;
import io.harness.query.PersistentQuery;
import org.mongodb.morphia.query.Query;
public class DelegateTasksQuery implements PersistentQuery {
private Query<DelegateTask> query;
public static DelegateTasksQuery create(HPersistence persistence) {
return new DelegateTasksQuery(persistence.createQuery(DelegateTask.class)
.project(DelegateTaskKeys.uuid, true)
.project(DelegateTaskKeys.data_timeout, true));
}
private DelegateTasksQuery(Query<DelegateTask> query) {
this.query = query;
}
public static class Final {
DelegateTasksQuery self;
Final(DelegateTasksQuery self) {
this.self = self;
}
public Query<DelegateTask> query() {
return self.query;
}
}
public static class FilterStatus {
DelegateTasksQuery self;
FilterStatus(DelegateTasksQuery self) {
this.self = self;
}
public Final status(DelegateTask.Status status) {
self.query.filter(DelegateTaskKeys.status, status);
return new Final(self);
}
}
public static class FilterUuids {
DelegateTasksQuery self;
FilterUuids(DelegateTasksQuery self) {
this.self = self;
}
public FilterStatus uuids(Iterable<String> uuids) {
self.query.field(DelegateTaskKeys.uuid).in(uuids);
return new FilterStatus(self);
}
}
public FilterUuids accountId(String accountId) {
query.filter(DelegateTaskKeys.accountId, accountId);
return new FilterUuids(this);
}
}
`
var outputContentWithDelegateId string = `
package io.harness.beans;
import io.harness.beans.DelegateTask.DelegateTaskKeys;
import io.harness.persistence.HPersistence;
import io.harness.query.PersistentQuery;
import org.mongodb.morphia.query.Query;
public class DelegateTasksQuery implements PersistentQuery {
private Query<DelegateTask> query;
public static DelegateTasksQuery create(HPersistence persistence) {
return new DelegateTasksQuery(persistence.createQuery(DelegateTask.class)
.project(DelegateTaskKeys.uuid, true)
.project(DelegateTaskKeys.data_timeout, true));
}
private DelegateTasksQuery(Query<DelegateTask> query) {
this.query = query;
}
public static class Final {
DelegateTasksQuery self;
Final(DelegateTasksQuery self) {
this.self = self;
}
public Query<DelegateTask> query() {
return self.query;
}
}
public static class FilterStatus {
DelegateTasksQuery self;
FilterStatus(DelegateTasksQuery self) {
this.self = self;
}
public Final status(DelegateTask.Status status) {
self.query.filter(DelegateTaskKeys.status, status);
return new Final(self);
}
}
public static class FilterDelegateId {
DelegateTasksQuery self;
FilterDelegateId(DelegateTasksQuery self) {
this.self = self;
}
public FilterStatus delegateId(String delegateId) {
self.query.filter(DelegateTaskKeys.delegateId, delegateId);
return new FilterStatus(self);
}
}
public static class FilterUuids {
DelegateTasksQuery self;
FilterUuids(DelegateTasksQuery self) {
this.self = self;
}
public FilterDelegateId uuids(Iterable<String> uuids) {
self.query.field(DelegateTaskKeys.uuid).in(uuids);
return new FilterDelegateId(self);
}
}
public FilterUuids accountId(String accountId) {
query.filter(DelegateTaskKeys.accountId, accountId);
return new FilterUuids(this);
}
}
`




// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "qbc",
Expand Down Expand Up @@ -184,12 +41,9 @@ func generateFile(cmd *cobra.Command) error {
fmt.Println(err)
}

var outputContent = ""
if strings.Contains(string(data), "filter String delegateId") {
outputContent = outputContentWithDelegateId;
} else {
outputContent = outputContentWithoutDelegateId;
}
var query = parser.Parse(string(data))
var compiler = compiler.Compiler{}
var outputContent = compiler.Generate(&query)

fmt.Println("Writing file at path [" + outputFilePath +"]")
err = ioutil.WriteFile(outputFilePath, []byte(outputContent), 0777)
Expand Down
3 changes: 1 addition & 2 deletions src/dom/parser/lexer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package parser

import (
"fmt"
"github.com/query-builder-generator/src/dom"
"text/scanner"
)
Expand Down Expand Up @@ -44,7 +43,7 @@ func (l *Lexer) Lex(lval *DomSymType) int {
}
}
lval.token = Token{token: tok, literal: lit}
fmt.Printf("Scanner: %+v, token: %+v, lit: %+v, tok: %+v \n", l.Scanner, token, lit, tok)
//fmt.Printf("Scanner: %+v, token: %+v, lit: %+v, tok: %+v \n", l.Scanner, token, lit, tok)
return tok
}
func (l *Lexer) Error(e string) {
Expand Down
45 changes: 45 additions & 0 deletions src/examples/foo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.harness.beans;

import io.harness.beans.DelegateTask;
import io.harness.beans.DelegateTask.DelegateTaskKeys;
import io.harness.persistence.HPersistence;
import io.harness.query.PersistentQuery;
import org.mongodb.morphia.query.Query;

public class DelegateTaskSelectQuery implements PersistentQuery {
public static SelectQueryString create(HPersistence persistence) {
return new QueryImpl(persistence.createQuery(DelegateTask.class));
}

public interface SelectQueryString {
SelectQueryInt string(accountId string);
}
public interface SelectQueryInt {
SelectQueryFinal int(delegateId int);
}
public interface SelectQueryFinal {
Query<DelegateTask> query();
}

private static class QueryImpl implements SelectQueryString, SelectQueryInt, SelectQueryFinal {
Query<DelegateTask> query;

private QueryImpl(Query<DelegateTask> query) {
this.query = query;
}

public SelectQueryInt string(accountId string) {
query.filter(DelegateTaskKeys.string, string);
return this;
}

public SelectQueryFinal int(delegateId int) {
query.filter(DelegateTaskKeys.int, int);
return this;
}

public Query<DelegateTask> query() {
return query;
}
}
}
5 changes: 5 additions & 0 deletions src/examples/simplequery.qbg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query Select for io.harness.beans.DelegateTask
{
filter accountId as string from list ;
filter delegateId as int from list ;
}

0 comments on commit f4235c3

Please sign in to comment.