Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/INTELLIJ-151-agg…
Browse files Browse the repository at this point in the history
…regates-unwind-stage
  • Loading branch information
himanshusinghs committed Nov 26, 2024
2 parents 87f30f9 + 57c62bc commit 7f7bbd9
Show file tree
Hide file tree
Showing 14 changed files with 1,248 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,137 @@ 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"
},
)
}

@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,139 @@ 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"
},
)
}

@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;
Expand Down
Loading

0 comments on commit 7f7bbd9

Please sign in to comment.