Skip to content

Commit

Permalink
chore: tests and minor suggestions for INTELLIJ-128 (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshusinghs authored Nov 25, 2024
1 parent 1f4c4ae commit d8a9dc0
Show file tree
Hide file tree
Showing 6 changed files with 802 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -805,4 +805,135 @@ public class Repository {
},
)
}

@ParsingTest(
fileName = "Repository.java",
value = """
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Aggregates;
import com.mongodb.client.model.Projections;
import com.mongodb.client.model.Sorts;
import org.bson.Document;
import org.bson.types.ObjectId;
import java.util.List;
import static com.mongodb.client.model.Filters.*;
import static com.mongodb.client.model.Updates.*;
public class Repository {
private final MongoClient client;
public Repository(MongoClient client) {
this.client = client;
}
public void exampleFind() {
client.getDatabase("myDatabase").getCollection("myCollection")
.aggregate(List.of(
Aggregates.group(
"<caret>"
)
));
}
}
""",
)
fun `should autocomplete fields from the current namespace for _id expression in Aggregates#group stage`(
fixture: CodeInsightTestFixture,
) {
fixture.specifyDialect(JavaDriverDialect)

val (dataSource, readModelProvider) = fixture.setupConnection()
val namespace = Namespace("myDatabase", "myCollection")

`when`(
readModelProvider.slice(eq(dataSource), eq(GetCollectionSchema.Slice(namespace)))
).thenReturn(
GetCollectionSchema(
CollectionSchema(
namespace,
BsonObject(
mapOf(
"myField" to BsonString,
),
),
),
),
)

val elements = fixture.completeBasic()

assertTrue(
elements.containsElements {
it.lookupString == "myField"
},
)
}

@ParsingTest(
fileName = "Repository.java",
value = """
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Accumulators;import com.mongodb.client.model.Aggregates;
import com.mongodb.client.model.Projections;
import com.mongodb.client.model.Sorts;
import org.bson.Document;
import org.bson.types.ObjectId;
import java.util.List;
import static com.mongodb.client.model.Filters.*;
import static com.mongodb.client.model.Updates.*;
public class Repository {
private final MongoClient client;
public Repository(MongoClient client) {
this.client = client;
}
public void exampleFind() {
client.getDatabase("myDatabase").getCollection("myCollection")
.aggregate(List.of(
Aggregates.group(
"${'$'}year",
Accumulators.sum("totalMovies", "<caret>")
)
));
}
}
""",
)
fun `should autocomplete fields from the current namespace for accumulator expression in Aggregates#group stage`(
fixture: CodeInsightTestFixture,
) {
fixture.specifyDialect(JavaDriverDialect)

val (dataSource, readModelProvider) = fixture.setupConnection()
val namespace = Namespace("myDatabase", "myCollection")

`when`(
readModelProvider.slice(eq(dataSource), eq(GetCollectionSchema.Slice(namespace)))
).thenReturn(
GetCollectionSchema(
CollectionSchema(
namespace,
BsonObject(
mapOf(
"myField" to BsonString,
),
),
),
),
)

val elements = fixture.completeBasic()

assertTrue(
elements.containsElements {
it.lookupString == "myField"
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -818,4 +818,137 @@ public class Repository {
},
)
}

@ParsingTest(
fileName = "Repository.java",
value = """
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Aggregates;
import com.mongodb.client.model.Projections;
import com.mongodb.client.model.Sorts;
import org.bson.Document;
import org.bson.types.ObjectId;
import java.util.List;
import static com.mongodb.client.model.Filters.*;
import static com.mongodb.client.model.Updates.*;
public class Repository {
private final MongoClient client;
public Repository(MongoClient client) {
this.client = client;
}
public void exampleFind() {
client.getDatabase("myDatabase").getCollection("myCollection")
.aggregate(List.of(
Aggregates.group(
<caret>
)
));
}
}
""",
)
fun `should autocomplete fields from the current namespace for _id expression in Aggregates#group stage`(
fixture: CodeInsightTestFixture,
) {
fixture.specifyDialect(JavaDriverDialect)

val (dataSource, readModelProvider) = fixture.setupConnection()
val namespace = Namespace("myDatabase", "myCollection")

`when`(
readModelProvider.slice(eq(dataSource), eq(GetCollectionSchema.Slice(namespace)))
).thenReturn(
GetCollectionSchema(
CollectionSchema(
namespace,
BsonObject(
mapOf(
"myField" to BsonString,
),
),
),
),
)

fixture.type('"')
val elements = fixture.completeBasic()

assertTrue(
elements.containsElements {
it.lookupString == "myField"
},
)
}

@ParsingTest(
fileName = "Repository.java",
value = """
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Accumulators;import com.mongodb.client.model.Aggregates;
import com.mongodb.client.model.Projections;
import com.mongodb.client.model.Sorts;
import org.bson.Document;
import org.bson.types.ObjectId;
import java.util.List;
import static com.mongodb.client.model.Filters.*;
import static com.mongodb.client.model.Updates.*;
public class Repository {
private final MongoClient client;
public Repository(MongoClient client) {
this.client = client;
}
public void exampleFind() {
client.getDatabase("myDatabase").getCollection("myCollection")
.aggregate(List.of(
Aggregates.group(
"${'$'}year",
Accumulators.sum("totalMovies", <caret>)
)
));
}
}
""",
)
fun `should autocomplete fields from the current namespace for accumulator expression in Aggregates#group stage`(
fixture: CodeInsightTestFixture,
) {
fixture.specifyDialect(JavaDriverDialect)

val (dataSource, readModelProvider) = fixture.setupConnection()
val namespace = Namespace("myDatabase", "myCollection")

`when`(
readModelProvider.slice(eq(dataSource), eq(GetCollectionSchema.Slice(namespace)))
).thenReturn(
GetCollectionSchema(
CollectionSchema(
namespace,
BsonObject(
mapOf(
"myField" to BsonString,
),
),
),
),
)

fixture.type('"')
val elements = fixture.completeBasic()

assertTrue(
elements.containsElements {
it.lookupString == "myField"
},
)
}
}
Loading

0 comments on commit d8a9dc0

Please sign in to comment.